"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Wednesday, February 17, 2010

Check Prime Number


#include<iostream.h>
#include<conio.h>
#include<process.h>

void main()
{
int n, flag = 0, r;

clrscr();

cout<< "\n Enter a number :";
cin>> n;

if(n == 1)
{
cout<< " 1 is neither prime or non-prime no.";
getch();
exit(1);
}

for(int i = 2; i< = n-1 ; i++)
{
r = n%i;
if(r == 0)
{
flag = 1;
break;
}
}

if(flag == 0)
cout<< "\n "<< n << " is a Prime No. ";
else
cout<< "\n "<< n << " is a NON-Prime No. ";

getch();

}

No comments:

Post a Comment

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.