fork download
  1. /*
  2.   Write a program to check if a given number is prime or not.
  3. */
  4.  
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. int n;
  11. cout << "Enter a Number: ";
  12. cin >> n;
  13.  
  14. int i;
  15. for (i = 2; i < n; i++)
  16. {
  17. if (n % i == 0)
  18. {
  19. cout << "Not a Prime" << endl;
  20. }
  21. }
  22. if (i == n)
  23. {
  24. cout << "Prime Number!" << endl;
  25. }
  26. return 0;
  27. }
Success #stdin #stdout 0.01s 5312KB
stdin
17
stdout
Enter a Number: Prime Number!