Here is the C++ program to print first 10 prime numbers.
#include<iostream> using namespace std; int main() { int i,j,count=1,b=0; cout<<"First Ten Prime Numbers Are\n"<<"2"; for(i=3;i>0;++i) { for(j=2;j<=i/2;++j) { if(i%j==0){ b=1; break; } } if(b==0) { cout<<"\n"<<i; count++; } b=0; if(count==10) break; } return 0; }
Output
First Ten Prime Numbers Are
2
3
5
7
11
13
17
19
23
29
2
3
5
7
11
13
17
19
23
29
these programs are quite helpful
Helpful indeed
i will be regular from now on. very very helpful
can you tell me why you had taken i=3
Already “2” has been printed as it is prime number so we start from i=2.
Bxoz we know 0,1 are not prime nos and 2 is smallest prime no hence we are checking the numbers from 3 onwards
can u tell me why are u taken i=3. and j=2
can u tell me why are u taken i=3. and j=2