Sep 27, 2013

Find Prime number with C++ Program

Unknown | 4:10 PM |
Do you know what is a prime number?
A natural number greater than 1 which has only two divisors 1 and it is called a prime number. For example: 7 is a prime number. Because it has only two divisors 1 and 7 (itself).




Now I am going to tell you how to find a prime number by using C++ program. Just type these code below

//C++ Program to find Prime number
#include<iostream.h>
#include<conio.h>
        void main()
        {
         //clrscr();
         int number,count=0;
cout<<"Enter number to check it is Prime or not ";
          cin>>number;
           for(int a=1;a<=number;a++)
               {
                if(number%a==0)
                   {
                  count++;
                   }
               }
       if(count==2)
         {
          cout<<" PRIME NUMBER \n";
         }
       else
         {
          cout<<" NOT A PRIME NUMBER \n";
         }
       //getch();
       }

Thanks! 

No comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

Search