Please support our C++ advertiser: Programming Forums
Views: 15410 | Replies: 20
•
•
Join Date: Jun 2005
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
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.....
<< moderator edit: added [code][/code] tags >>
I need all the help i can get
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;
}I need all the help i can get
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Threaded Mode