write a program to check whether entered number is prime or not

Prime number: A natural number which has exactly two distinct natural number divisors: 1 and itself.
A number is taken from user and is checked whether prime number or not.


Select To use this code as it is.. select and copy paste this code into code.cpp file :)



  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int n,m;
  7. cout<<"Please enter a number: ";
  8. cin>>n;
  9. for (int i=2;i<=(n-1);i++)
  10. {
  11. if(n%i==0)
  12. //Coding by: Snehil Khanor
  13. //http://WapCPP.blogspot.com
  14. {
  15. cout<<"Not a prime";
  16. break;
  17. }
  18. else
  19. {
  20. cout<<"Prime";
  21. break;
  22. }
  23. }
  24. getch();
  25. }

Check out this stream