Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.
C++ Prime numbers hlp plz?
Print out the odd numbers?..
#include <iostream>
int main(int argc, char **argv)
{
for(int i=1; i<=1000; ++i)
if((i%2) != 0) std::cout << i << " ";
return 0;
}
or if you meant the prime numbers, than I guess you could do something like..
#include <iostream>
int main(int argc, char **argv)
{
for(int i=1; i<=1000; ++i)
{
int nFactors = 0;
for(int ii=1; ii<=i; ++ii)
if((i%ii) == 0) ++nFactors;
if(nFactors <= 2) std::cout << i << " ";
}
return 0;
}
Here you go.
http://www.freewebs.com/uber0n/Source/Prime_Counter_src.zip
This can easily be edited to match your needs :)
ahhhh your absolutly right metal, thank you for recognizing my mistake. my keyboard is messed up right now, and it took forever to type out a message, then when i hit enter i got that "unable to connect to sql server" error… so i had to redo it all lol,
thank you very much for the quick responses both of you. i really appreciate it
dont know if this will help, but it is a divisibility checker that i wrote a while ago. i think that you could take the for loop from it and change to what you need:
#include <iostream>
using namespace std;
void CheckDivis (int num)
{
int a;
for(int i=2; i<=10; ++i) {
a=num%i;
if (a!=0) cout<<"not divisible by "<<i<<endl;
else cout<<"divisible by "<<i<<endl;
}
}
int main ()
{
int b;
cout<<"CheckDivis:";
cin>>b;
if(b>100000000) {cout<<"Number too large\n"; system("PAUSE"); return 0;}
CheckDivis(b);
cout<<endl;
main ();
}