fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n = 29;
  6. int cnt = 0;
  7.  
  8. // If number is less than/equal to 1,
  9. // it is not prime
  10. if (n <= 1)
  11. cout << n << " is NOT prime";
  12. else {
  13.  
  14. // Count the divisors of n
  15. for (int i = 1; i <= n; i++) {
  16. if (n % i == 0)
  17. cnt++;
  18. }
  19.  
  20. // If n is divisible by more than 2
  21. // numbers then it is not prime
  22. if (cnt > 2)
  23. cout << n << " is NOT prime";
  24.  
  25. // else it is prime
  26. else
  27. cout << n << " is prime";
  28. }
  29. return 0;
  30. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
29 is prime