Respuesta :
Answer:
The program to this question can be given as:
program:
#include <iostream> //define header file.
using namespace std;
int isPrime (int number); //declare function.
int isPrime(int number) //function definitation.
{
int i;
if(number<1) //conditional statements.
return false;
else if (number == 1||number ==2 ||number==3)
{
return true;
}
else
{
for(i=2; i<number; i++)
{
if(number%i==0)
return false;
}
return true;
}
}
int main () //main method.
{
int number=0; //declare variable.
cout << "Enter a number for check it is prime number or not : "; //print message.
cin >> number; //input by user.
if (isPrime(number)==true) //check condition.
cout << number << " is prime.";
else
cout << number << " is NOT prime.";
return 0;
}
Output:
Enter a number for check it is prime number or not : 3
3 is prime.
Explanation:
In this program we define a function that is (isPrime()).In this function, we pass the user input as a parameter. Then we use conditional statement in these statements we check the number is divisible by itself and 1.If the number is divisible it returns true otherwise it returns false. In the last we define the main function in that function we take user input and pass it in the function, and print its return value.