Answer:
#include <iostream>
using namespace std;
int main() {
int n;
cin>>n;//taking input form the user.
bool b=true;
for(int i=2;i<n;i++)//looping
{
if(n%i==0)//checking that i divides n.
{
cout<<"The number is not prime";
b=0;
break;
}
}
if(b)
{
cout<<"The number is prime";
}
return 0;
}
Input:-
23
Output:-
The number is prime.
Explanation:
The above written program is in C++.First I have declared an integer n.Then taking input form the user and storing it in n abd also declared a boolean variable with value true.Then I have used a for loop for checking n is divisible by any number from 2 to n-1 if it is then printing the message of not prime,making the value of b to false and coming out of the loop.out of the loop if the value of the b is true then printing the number is prime.