Friday 16 November 2012

Prime or Composite With "bool" data type using NOT operator.


//3rd logic with NOT Logical Operator and bool Data Type.
#include <iostream>
#include <process.h>
using namespace std;
int main()
{
int n;
bool check=false;
cout << "Enter Any +ve Integer: ";
cin >> n;
if (n < 0)
{
cout << "STOP !!!! Plz Enter Correct Number Value."<<endl;
exit(1);
}
for (int j=2;j<=n/2;j++)
{
if (n%j==0)
{
check=true;
break;
}
}
if (check!=true)
cout << n << " is a Prime Number.\n";
else
cout << n << " is a Composite Number.\n";
return 0;
}

No comments:

Post a Comment