fork download
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. bool isPrime(int prime);
  7. int main(int argc, char *argv[])
  8. {
  9. int prime;
  10. cout << "Enter an integer: ";
  11. cin >> prime;
  12. //bool isPrime(prime);
  13. if (isPrime(prime)) {
  14. cout << prime << " is a prime number." << endl;
  15. }
  16. else {
  17. cout << prime << " is not a prime number." << endl;
  18. }
  19. //system("PAUSE");
  20. return EXIT_SUCCESS;
  21. }
  22. bool isPrime(int prime){
  23. for (int divisor = 2; divisor <=prime/2; divisor++) {
  24. if (prime%divisor==0)
  25. return 0;
  26. }
  27. return true;
  28. }
Success #stdin #stdout 0s 3344KB
stdin
12
stdout
Enter an integer: 12 is not a prime number.