Answer:
Explanation:
The objective is to write a Matlab function getPrime()
CODE:
function prime = getPrime(x) %function definition for getPrime which receives x as input and returns prime.
while (x >= 1) % loop until x is zero.
if isprime(x) % matlab built-in function to check if x is a prime number.
prime = x; % assign x to prime.
break % break out of loop. we got the prime number value in variable prime.
end
x = x - 1; % when x is not prime, x is decremented by 1 and loop continues.
end
end
prime = getPrime(12); % passes 12 to function.
disp(prime) % display value in prime. 11 is the output since it is the biggest prime number below 12.