C++ Program to Find Prime Number Or Not

This c++ program checks if a number is a prime or not. A number which is greater than 1 and can only be divided by 1 and itself are prime numbers. These prime numbers include 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 and so on. A FOR loop is implemented in this program. If the number entered by the user can be divided by another number that is within its range to give zero as the remainder then, this number is not a prime number.

#include <iostream.h>
#include <math.h>
void main()
int num, a=0;
cout<<"enter a number: ";
for(int i=2;i<num;i++)//loop begins at 2 since 1 can divide any number
   cout<<num<<" is a prime number";
  cout<<num<<"is not a prime";

Do you like this post? Please link back to this article by copying one of the codes below.

URL Of Post:

HTML Link Code:

BB (forum) link code: