Prime number up to N number using c++

 Let's see the prime number program in C++. In this C++ program, we will take an input from the user and Print series of prime numbers up to N number.

#include <iostream>  
using namespace std;  

int main()  
{  
  int n, i, j; 
  cout << "Enter the a Number:  ";  
  cin >> n;  
  cout << "Series of prime numbers up to "<<n<<"is "<<endl ;
  for(i = 2; i <= n; i++)  
  {  
      for(j=2;j<=i;j++)  
      {  
           if (i%j==0)  
             break;  
      }  
   }  
   if (i==j)  
      cout << "  "<<i;  
  return 1;  

Output:

Enter the a Number:   30

Series of prime number up to 30 is 2 3 5 7 11 13 17 19 23 29


1 comment: