C++ program to find the prime number...
C++ program to find the prime number...
Prime number:
A number which is only divisible by 1 and itself. e.g 3,5,7#include <iostream>
using namespace std;
int main()
{
int user,count=1;
cout<<"Enter a number:"<<"\n";
cin>>user;
for(int i=2; i<=user; i++)
{
for(int j=2; j<=i; j++)
{
if(i%j==0)
{
if(i==2)
{
cout<<"\n"<<i<<"\n";
}
break;
}
else if(i==j+1)
{
cout<<i<<"\n";
count++;
}
}
}
cout<<"\n Above first "<<count<<" prime number"<<"\n";
return 0;
}
Comments
Post a Comment