Is it prime
Inputs
n is a whole number from 0 to 400.
Your tasks
- If
nis less than 2, return false. - Use a loop over each whole number
dfrom 2 up whiled * dis at mostn. Ifddividesnevenly, return false right away. - If the loop ends without finding a divisor,
nis prime. - Complete
isPrimeso it returns true or false. Return it, do not print it.
Example
With n = 13, isPrime returns true.
Rules
- 0 and 1 are not prime.
Test data
TEST DATA 1: n is 13
TEST DATA 2: n is 1
Practice focus
While loops and early exits, for when you don't know how many rounds you need. Binary search, the Euclidean algorithm and graph search are all while loops with a clear stopping rule.