Friday 6 September 2013

a simple c++ program to find whether or not a given no. is prime

#include<iostream.h>
#include<conio.h>
void main()
{
       int n,count=0;
       cin>>n;
       for(int i=1;i<=n;i++)
       {
         if(n%i==0)
          count++;
        }
        if(count==2)
        {
         cout<<"the no. you entered is prime..";
        }
         else
        {
         cout<<"not a prime....";
         }
          getch();


No comments:

Post a Comment