Sunday 26 July 2015

  • Sunday, July 26, 2015

C++ programming code

#include<iostream>
#include<cmath>
 
using namespace std;
 
int main()
{
   int n, status = 1, num = 3, count, c;
 
   cout << "Enter the number of prime numbers to print\n";
   cin >> n;
 
   if ( n >= 1 )
   {
      cout << "First " << n <<" prime numbers are :-" << endl;
      cout << 2 << endl;
   }
 
   for ( count = 2 ; count <=n ;  )
   {
      for ( c = 2 ; c <= (int)sqrt(num) ; c++ )
      {
         if ( num%c == 0 )
         {
            status = 0;
            break;
         }
      }
      if ( status != 0 )
      {
         cout << num << endl;
         count++;
      }
      status = 1;
      num++;
   }         
 
   return 0;
}
Related Posts Plugin for WordPress, Blogger...

Vacancy

RBI has announced the recruitment for 134 GRADE B OFFICERS.
 The examination will be in two phases.
 The detailed advertisement will be published on 5th October.

Popular Posts