A prime is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Prime number is always a Positive Integer.
For Example: 3,5,7,11,13 etc.
Here is how to find Prime numbers in C++
using namespace std;
bool isPrime(int n)
{
// Check if given nmbr is less than or equal to 1 (prime nmbr is always greater than 1)
if (n <= 1)
return false;
// Check from 2 to n-1
for (int i = 2; i < n; i++)
if (n % i == 0)
return false;
return true;
}
int main()
{
isPrime(11) ? cout << "Prime\n" : cout << "Not Prime\n";
isPrime(7) ? cout << " Prime\n" : cout << "Not Prime\n";
return 0;
}