Write a program to enter any number and check whether the number is prime number or not
#include <iostream>
using namespace std;
bool isPrimeNumber(int number)
{
if(number == 1)
return false;
if(number == 2)
return true;
for(int i = 2; i < number; i++)
{
if(number%i == 0)
return false;
}
return true;
}
int main()
{
cout << "number = ";
int number;
cin >> number;
cout << endl;
if(isPrimeNumber(number))
cout << number << " is a prime number";
else
cout << number << " is not a prime number";
cout << endl << endl;
return 0;
}
Comments
Leave a comment