CodeMIRAI
0 XP

Primes up to n

Hard +80 XP Solved

Read n (at least 2) and print every prime number from 2 to n on one line, separated by spaces.

Input
10
Expected output
2 3 5 7
Input
2
Expected output
2
Show a hint

Write an is_prime function that tries divisors up to the square root, then loop from 2 to n.

Show a solution
C
Loading the editor…
Run the tests to check your solution.