BY LOOPS
Write a program that ask the user to type a value and check whether it is prime or not.
#include <iostream>
int main() {
int x;
std::cout << "Enter the integer: ";
std::cin >> x;
bool found = false;
for (long long i = 2LL; i * i <= (long long)x && !found; i++) {
found = x % i == 0;
}
std::cout << (found? "It's not a prime!\n" : "It's a prime number\n");
return 0;
}
Comments
Leave a comment