Tuesday, 25 February 2014

Tagged Under: ,

Program To Find Whether A Number Is Prime Or Not

Share



What is a
PRIME NUMBER?


" A Natural number greater than 1 which has only two divisor 1 and itself is called prime number ".
For Example:  
5 is prime, because it has only two divisors 1 and itself.

Source Code
    #include<iostream>
    #include<conio.h>
    using namespace std;
            int 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();
           }


Output


0 comments:

Post a Comment

Contact Us

Want to ask anything? Be our guest, give us a message.

Name Email * Message *