Can someone help me to make program to count how many primes in 3 random numbers? | Sololearn: Learn to code for FREE!
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

16th Apr 2018, 9:29 AM
Tio
Tio - avatar
4 ответов
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))
16th Apr 2018, 9:54 AM
Bartosz Pieszko
Bartosz Pieszko - avatar
0
yas
16th Apr 2018, 9:55 AM
Tio
Tio - avatar
0
Done.
16th Apr 2018, 10:04 AM
Bartosz Pieszko
Bartosz Pieszko - avatar
0
thank you
16th Apr 2018, 10:05 AM
Tio
Tio - avatar