C++ Prime Number  Program without function
//Prime Number : A number which is divisible by 1 and itself only called Prime Number.

#include <iostream.h>
#include <conio.h>

void main( )
{
        int number, prime=1;
        cout  << "Enter a Number :: ";
        cin >> number;
     
         for( int d = 2; d <= number / 2; d++ )
         {
                     if ( number % d = = 0)
                     {
                                   prime = 0;
                                   break;
                      }
          }
          if ( prime ) // if( prime = = 1) /// here 1 is treated as true
                    cout << "YES Given Number is PRIME NUMBER ";
          else
                    cout << "NO Given Number is NOT A PRIME NUMBER ";
          getch( );

}

Post a Comment

Previous Post Next Post