fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, i;
  6. bool isPrime = true;
  7.  
  8. cout << "Enter a positive integer: ";
  9. cin >> n;
  10.  
  11. for(i = 2; i <= n / 2; ++i)
  12. {
  13. if(n % i == 0)
  14. {
  15. isPrime = false;
  16. break;
  17. }
  18. }
  19. if (isPrime)
  20. cout << "This is a prime number";
  21. else
  22. cout << "This is not a prime number";
  23. // your code goes here
  24. return 0;
  25. }
Success #stdin #stdout 0s 15224KB
stdin
10000009
stdout
Enter a positive integer: This is not a prime number