Hello guys,
I need some help with a program that finds all the prime numbers from 2 to 10000,here is what I have so far

#include <iostream>
using namespace std;
bool prime(int n );




void main ()
{
int n,b;
b=0;
for (n=2;n<=10000;n++)
prime (n);
if ()
{
cout<<n<<endl;
b=b+1;

 }
 cout <<b;
   }
   
bool prime (int n)
{
int i;
for (i=2;i<=100;i++)
{
if(n%i==0)
return false;
}

return true;
}

any help would be much aprreciated ,thanks!

ok I think this much better at least I get results :P ,I dont know what was I thinking when I was writing the old one,anyways here is the new

#include <iostream>
using namespace std;
int prime(int i );




void main ()
{
int c,z;
for (c=2;c<=10000;c++)
{
z=prime (c);

if (z=1)
cout<<c;
}
}

int prime (int n)
{
int x;
for(x=2;x<=n;x++ )
{if (n%x==0)
return 0;
else
return 1;
}
}

Can you please check if it is correct .Thanks alot

#include <iostream>
using std::cout;
using std::endl;
using std::cin;


#include <cmath>


#include<iomanip>
using std::setw;


bool prime(int n);


int main()
{
int count = 0;


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


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


if (prime(x))
{
++count;


cout << setw( 6 ) << x;



if ( count % 5 == 0)
cout << endl;
}
cout << "\nThere were " << count << " prime numbers tested\n" << endl;


return 0;
}
bool prime (int n)
{
for ( int z = 2; z<=sqrt(double(n)); z++)


if( n%z == 0 )
return false;


return true;
}

Thank alot mate ,cheers !!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.