fork download
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. bool isPrime(int num) {
  5. int j;
  6.  
  7. for (j = 2; j < ((static_cast<int>(sqrt(num)) + 1)); j++) {
  8. if ((num % j) == 0) return false;
  9. }
  10.  
  11. return true;
  12. }
  13.  
  14. int main(int argc, char** argv) {
  15. std::cout << isPrime(2) << std::endl;
  16. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
1