Searching...

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

15:33

//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;
}

0 comments:

Post a Comment

Thanks For Your FeedBack....

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.