C++ Program to find Prime numbers

ad+1

Before coding the program lets discuss about prime numbers. Prime numbers are those number which are divisible by 1 and itself.

Note: 1 is not a prime number. Prime numbers starts with 2.

 

 Program:

// Program By http://solutionscpp.blogspot.com
// Author Mansoor Ahmed
// GMail ID: secguy000@gmail.com


#include <iostream>
using namespace std;

int main()
{

  int n=0, check=0;

  cout << "Enter Number: ";
  cin >> n;

  for(int i=2;i<=n/2;++i)
  {
      if(n%i==0)
      {
          check=1;
          break;
      }
  }

  if (check==0)
      cout << "This is a prime number";

  else
      cout << "This is not a prime number";

  return 0;
}


Output:

 

0 comments: