//Prime Number Checker in C++. Program to check whether Entered Number is Prime Number or not.
#include <iostream>
using namespace std;
int main()
{
cout <<"Enter a Number, I'll tell u, whether it's Prime or Not: ";
int x;
cin>>x;
bool n=0;
for (int i = 2; i<= (x-1); i++)
{
if ( x%i == 0 )
{
n = 1;
break;
}
}
cout << x << ((n==1)? " is not ": " is ") << "prime number"<<endl;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
cout <<"Enter a Number, I'll tell u, whether it's Prime or Not: ";
int x;
cin>>x;
bool n=0;
for (int i = 2; i<= (x-1); i++)
{
if ( x%i == 0 )
{
n = 1;
break;
}
}
cout << x << ((n==1)? " is not ": " is ") << "prime number"<<endl;
return 0;
}
No comments:
Post a Comment