Complete the code to check if a number is less than 2, which means it is not prime.
if (num [1] 2) { return false; }
If the number is less than 2, it is not prime.
Complete the for loop to check divisors from 2 up to the square root of the number.
for (int i = 2; i [1] Math.Sqrt(num); i++) { if (num % i == 0) { return false; } }
We need to check divisors up to the square root of the number (inclusive), so use '<='.
Fix the error in the return statement to correctly indicate the number is prime after the loop.
return [1];
After checking all divisors, if none divide the number, it is prime, so return true.
Fill both blanks to complete the method signature and the return type for checking prime.
public static [1] IsPrime(int num) { [2]
The method returns a boolean indicating if the number is prime, so the return type is bool and it returns true or false.
Fill all three blanks to complete the prime check method with initialization, loop condition, and return statement.
public static bool IsPrime(int num) {
if (num [1] 2) return false;
for (int i = 2; i [2] Math.Sqrt(num); i++) {
if (num % i == 0) return false;
}
return [3];
}The method returns false if number is less than 2, loops from 2 up to the square root, and returns true if no divisor found.
