Professional Documents
Culture Documents
C++ Program Prime No
C++ Program Prime No
#include <iostream>
int main()
int n, i;
cin >> n;
if(n % i == 0)
isPrime = false;
break;
if (isPrime)
else
return 0;
}
To check whether the number is a prime number or not a prime number in C++ programming,
you have to ask to the user to enter a number and start checking for prime number.
If number is divisible by 2 to one less than that number (n-1), then the number is not prime n
umber, otherwise it will be a prime number.
Following C++ program ask the user to enter a number to check whether it is a prime number
or not, then display it on the screen: