Friday 16 November 2012

Prime or Composite........


// 2nd Logic To check prime or composite
#include <iostream>
#include <process.h>
using namespace std;
int main()
{
int n,counter=0;
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)
{
counter++;
break;
}
}
if (counter==0 && n!=0)
cout << n << " is a Prime Number.\n";
else
cout << n << " is a Composite Number.\n";
return 0;
}

No comments:

Post a Comment