Write the MATLAB code necessary to solve this problem for the zombie or he will eat your brain. Create a function with an input of the target number (in the scenario given above the target number would be 10,000), which outputs the last numbered added.

Respuesta :

Answer:

x = 1;

sum = 1;

while sum <=10000

x = x+2;

sum = sum + x;

end

a = sprintf('last number = %d\nthe sum would be = %d',x,sum);

disp(a)

Explanation:

  • Start with 1 as the initial sum .
  • Inside the while loop, apply the condition that will stop the loop as soon as sum exceeds the value 10,000 .
  • Finally add the next odd whole number  and print the result.