Wednesday 20 January 2016

// // Leave a Comment

PRIME NUMBER

C++ Program To Check Prime Number




#include <iostream>
#include<stdlib.h>
using namespace std;


int main()
{
unsigned n, i, flag = 0;
cout << "Enter a integer: ";
cin >> n;
if (n >= 2)
{

for (i = 1; i <= n; ++i)
{
if (n%i == 0)
{
++flag;
}
}
if (flag == 2)
cout << "This is a prime number" << endl;
else
cout << "This is not a prime number" << endl;
}
else
{
cout << "Wrong entry please press ENTER to enter again!\n ";
system("pause");
system("CLS");
main();
}
system("pause");
}

*------------------------------------------------------------------------------------------------------*






























0 comments:

Post a Comment