C++ Program to find if Entered Number is Prime
#include<iostream>
using namespace std;
int main()
{
int i,n,flag=0;
cout<<"=========================================\n";
cout<<"Enter a number to check if is it a prime number or not\n";
cout<<"=========================================\n";
cout<<"Enter N : ";
cin>>n;
for(i=2;i<n-1;i++)
{
if(n%i==0)
{
flag++;
break;
}
}
if(flag==0)
{
cout<<"Its a prime number";
}
else if(flag!=0)
{
cout<<"It's not a prime number";
}
}
Comments
Post a Comment