Saturday, 17 January 2015

Prime Number Program

#include<iostream>
using namespace std;

int main()
{ 
   int num,i=2,w=0;;
   cout<<"Enter Number :\t";
   cin>>num;
   if(num<2)
     cout<< " Not Prime \n";
   else
   {
     while(i<num)
     {
       if(num%i==0) w++;
       i++;
     } 
     if(w!=0)
         cout<< " Not Prime \n";
     else
         cout<< " Prime \n";
   }
   cout<<"\n\n";
   system("pause");
   return 0;
}



===========================================
How to Run:
Run this code through devc++ compiler.

0 comments:

Post a Comment