#include<iostream>
#include<conio.h>
using namespace std;
bool prime(int n);
int main()
{
int n;
cout<<"Enter any number : ";cin>>n;
if(prime(n)==1)
cout<<n<<" is a prime number.";
else
cout<<n<<" is not a prime number.";
getch();
return(0);
}
bool prime(int n)
{
if(n==0||n==1||n==2)
return(0);
else
{
for(int i=2;i<=(n/2);i++)
{
if(n%i==0)
return(0);
}
return(1);
}
}
No comments:
Post a Comment