<>

Write a program to print 1st 100 prime numbers.


Write a program to print 1st 100 prime numbers.
Hint: Use nested loops, break and continue.


#include<iostream.h>
void main()
{
    int x=1,c,i=0;

     cout<<"First 100 Prime numbers are: "<<endl;

     while(1)
     {
          for (c = 2 ; c <= x - 1 ; c++ )
          {
              if ( x%c == 0 )
                   break;
          }
         
          if ( c == x )
              cout<<++i<<" : "<<x<<endl;
         
          x=x+1;

          if(i==100)
              break;
     }
}
Rate this posting:
{[['']]}

0 comments:

Post a Comment

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.

 
TOP