Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- auto isPrime(int, int) -> bool;
- auto main(int argc, char** argv) -> int {
- int toCheck = 0;
- while(std::cin >> toCheck) {
- if(isPrime(toCheck, 2)) std::cout << "true" << std::endl;
- else std::cout << "false" << std::endl;
- }
- return 0;
- }
- auto isPrime(int n, int i) -> bool {
- if(n <= 2) return (n == 2) ? true : false;
- if(!(n%i)) return false;
- if(i*i > n) return true;
- return isPrime(n, i+1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement