#include <iostream>
bool is_prime(const int prime){
if (prime <= 0)
return false;
for(int i = 2; i <= prime / 2; i++)
if(prime % i == 0)
return false;
return true;
}
int main() {
int prime;
std::cout << "Enter any positive number: ";
std::cin >> prime;
if (is_prime(prime))
std::cout << prime << " is a prime number" << std::endl;
else
std::cout << prime << " is not a prime number" << std::endl;
return 0;
}
Comments
Leave a comment