Loading...

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

 
TOP