prime numbers code error..
hi people,
i was trying to have fun with some c++ codes....it seems easy but ..i really got stuck because i ididnt get the logic of the primary number..or in better way....how to convert that logic in logical statement.!
here is the code
# include <iostream.h>
# include <conio.h>
# include <iomanip.h>
bool prime(int n);
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 prime()
{
++count;
cout<<setw(6)<<loop;
if(count%10==0)
cout<<'\n';
} // end if
cout<<"\nthere were :"<<""<<count<<" "<<"prime numbers";
return 0;
}
bool prime(int n)
{
for(int i=2; i<=10000 ; i++)
if(//test if n is divisible by i//)
return false;
else
return true;
}
to test if n is divisible by n:
i have tried the following:
if(n%i!=0)
return fale
else return true;
i also have tried many logical statements but none of them work properly...so..i think i missing the logic of this..can anyone help me please?
thank you
|