Prime Number problem

This is a discussion on Prime Number problem within the C++ Programming forums, part of the General Programming Boards category; I am trying to figure out how to print all the prime numbers between 0 and 10000 on the screen. ...

  1. #1
    Unregistered
    Guest

    Red face Prime Number problem

    I am trying to figure out how to print all the prime numbers between 0 and 10000 on the screen. my thoughts were as follows:

    for(i=1; i<10000; i++)
    {
    if(i%10000==0)
    cout << i << endl;
    }

    it doens't work obviously. Any help woud be greatly appreciated... send an email to cnielsen@nmsu.edu

    Cole

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    8
    This should do it:
    Code:
    for(int i = 2; i < 10000; i++)
    {
      bool prime = true;
      for(int j = 2; j < i; j++)
      {
        if(i%j == 0)
         prime = false;		
      }
      if(prime)
        cout<<i<<endl;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Prime number algorithm
    By Akkernight in forum C Programming
    Replies: 9
    Last Post: 04-19-2009, 02:50 PM
  2. noob problem with a number generator
    By Amoreldor in forum C Programming
    Replies: 14
    Last Post: 03-10-2005, 10:39 AM
  3. prime # query
    By alokin in forum C Programming
    Replies: 8
    Last Post: 09-04-2002, 12:50 PM
  4. Random Number problem in number guessing game...
    By -leech- in forum Windows Programming
    Replies: 8
    Last Post: 01-15-2002, 05:00 PM
  5. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-26-2001, 12:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21