134k views
2 votes
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.

User Akoi Meexx
by
3.3k points

1 Answer

4 votes

Answer:

x = 1;

sum = 1;

while sum <=10000

x = x+2;

sum = sum + x;

end

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

disp(a)

Step-by-step 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.
User Muuvmuuv
by
3.4k points