C++ Programs & Stuffz

Nothing like anything!!!

Please Click on ADS!!

Please Click on the above ads given by GOOGLE , so that I can maintain my blog!!

Tuesday, August 31, 2010

Check whether the entered no. is a prime no. or not

//pgm to check whether the entered no. is a prime no. or not
#include<iostream.h>
#include<conio.h>
void main()
{
    int i,n,x=0;
   cout<<"enter the number";
   cin>>n;
   for(i=1;i<=n;i++)
   {
       if(n%i==0)
          x++;
   }
   if(x==2)
       cout<<n<<"is a prime no.";
   else
       cout<<n<<"is not a prime no.";
   getch();
}

0 comments:

Post a Comment

free counters