Answer:
I am writing a C++ program.
bool isPrime(int integer) //boolean function that takes integer argument //and returns true if argument is prime number otherwise false
{ if (integer > 1) // if the integer value is greater than 1
{ for (int i = 2; i <= integer; ++i)
//loop starts from 2 and iterates until the value of i gets greater than integer //value
{ if (integer % i == 0) // if integer value is completely divisible by i
{ if(integer == i) // if integer value is equal to i
return true; //function returns true
else //if integer value is not divisible by i
return false; //function returns false } } } } }
Step-by-step explanation:
In order to see the output of the program you can write a main() function as following:
int main() { //start of the main() function body
int integer; // int type variable integer
cout<< "Enter an integer: "; //prompts user to enter an integer value
cin >> integer; //reads the input from user
cout << integer<<" "; //prints the integer value entered by user
if (isPrime(integer))
// calls boolean function to check if the integer value is prime number or not
{ cout << " is a Prime number." << endl; }
//displays the message number is prime
else //if the integer value is not prime
cout << " is not a Prime number." << endl; } //displays message
The output along with the program is attached as screenshot.