0
Can someone help me to make program to count how many primes in 3 random numbers?
example: input are 5,17,25. output is 2
4 Answers
0
Tio
int result = 0, t[3] = {5, 17, 25};
for (int i = 0; i < 3; i++) {
bool ok = true;
for (int j = 2; j * j <= t[i]; j++)
if (t[i] % j == 0)
ok = false;
if (ok && t[i] > 1)
result++;
}
printf("%d\n", result);
Time complexity: O(n*sqrt(m))
0
yas
0
Done.
0
thank you