Friday, 27 July 2012

how to find prime number using c++


 This is the source code for finding prime number 
#include<iostream.h>
#include<conio.h>
main()
{
      int n,d,p=1;
      cout<<"enter the number?";
      cin>>n;
      d=2;
      while(d<=n/2)
      {
                   if(n%d==0)
                   p=0;
                   d++;
                   }
                   if(p==0)
                   cout<<"not prime number";
                   else
                   cout<<"prime number";
                   getch();
                   }
      End

No comments:

Post a Comment