#include<iostream>
using namespace std;
void prime()
{
int x, n= 3, tick, c;
cout <<"number of prime numbers needed: "; cin>> x;
if( x >= 1 )
{
cout <<"\nFirst " <<x <<" prime numbers:\n" <<2 <<endl;
}
for(tick= 2; tick<= x;)
{
for(c= 2; c<= n -1; c++)
{
if (n%c == 0) break;
}
if (c == n)
{
cout <<n <<endl;
tick++;
}
n++;
}
}
int main()
{
prime();
return 0;
}
using namespace std;
void prime()
{
int x, n= 3, tick, c;
cout <<"number of prime numbers needed: "; cin>> x;
if( x >= 1 )
{
cout <<"\nFirst " <<x <<" prime numbers:\n" <<2 <<endl;
}
for(tick= 2; tick<= x;)
{
for(c= 2; c<= n -1; c++)
{
if (n%c == 0) break;
}
if (c == n)
{
cout <<n <<endl;
tick++;
}
n++;
}
}
int main()
{
prime();
return 0;
}
No comments:
Post a Comment