RSS Forums RSS
Please support our C++ advertiser: Programming Forums
Views: 15410 | Replies: 20
Join Date: Jun 2005
Posts: 7
Reputation: dark7angelx07 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dark7angelx07 dark7angelx07 is offline Offline
Newbie Poster

Program that determines if a number is prime

  #1  
Jun 30th, 2005
Hi,
I need help writing a function that determines if a number is prime. It has to print all the prime numbers between 1 and 10000
this is what i have...where i put a " */* " is where i need your help.....

#include<iostream>

using std::cout;
using std::endl;

#include<iomanip>

using std::setw;

/* write prototype for function prime */

int main()
{
  int count = 0;

  cout << "The prime numbers from 1 to 10000 are:\n";

  for (int loop =2; loop <= 10000; ++loop)

     if ( /* make call to function prime */  ) {
        ++count;
        cout << setw( 6 ) << loop;

     if ( count % 10 == 0)
        cout << '\n';
}

  cout << '\n' << "There were " << count
         << " prime numbers\n";

 return 0;
}
  bool prime (int n)
{
  for ( int i = 2; /*write loop condition */; i++ )

     if( /*write code to test if n is divisible by i */)
        return false;

   return true;
}
<< moderator edit: added [code][/code] tags >>

I need all the help i can get
AddThis Social Bookmark Button
Reply With Quote  

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 11:13 am.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC