Advertisement
rorschack

c++ prac prog - 20

Aug 16th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <iostream.h>
  2. #include <conio.h>
  3.  
  4. int main()
  5. {
  6.     clrscr();
  7.     unsigned short int n;
  8.     bool prime(0);
  9.     cout << "Enter a positive integer to check if its prime or not: ";
  10.     cin >> n;
  11.     if(n<=1)
  12.         return 1;
  13.     for (int i(2); i<n; i++)
  14.         if(n%i==0)
  15.         {
  16.             prime = 1;
  17.             break;
  18.         }
  19.     if(prime == 0)
  20.         cout << "\nThe no. entered is Prime." << endl;
  21.     else
  22.         cout << "\nThe no. entered is NOT Prime." << endl;
  23.     getch();
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement