// demonstrates IF statement with prime numbers.
#include <iostream.h>
#include <process.h> // for exit ()
void main ()
{
unsigned long n, j;
cout << "enter a number: ";
cin >> n; // get number to test
for(j = 2;j <n/2;j++)
if(n%j==0)
{
cout << "It's not prime; divisible by " << j << endl;
exit(O); // exit from the program.
}
cout << "It's prime \n";
}
Output of the above program:
Enter a number: 13
It’s prime
Enter a number: 22231
It’s not prime ; divisible by
