Is the number simple?
-
I want to write a walk on C++. She first asks for a number (only or not, proga checks) and then turns the result to the console. Explain, please, how to do or at least give a hint (fare dev-c++ 4.9.9.2), please.
-
Write something in
int n; // ввести n c клавиатуры
for (i = 2; i<sqrt(n); i++) {
if (n % i == 0) {
// вывести, что n не простое, так как делится на i
return 0;
}
}
//вывести что n простое.
return 0;
Algorithm, of course, can be expedited at least twice, but it's enough for starters.