Thread: Prime Number problem

  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 [email protected]

    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, 01: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, 11:50 AM
  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-25-2001, 11:45 PM