univerity of winoisat chicago cs 109 Bea spring 2017: Programmingin MATLA and o
ID: 3787208 • Letter: U
Question
univerity of winoisat chicago cs 109 Bea spring 2017: Programmingin MATLA and o While loop: Summation write a while loop that assigns summedvalue with the sum of all values from 1 to userNurm. Assume userNum is always greater than or equal to 1. Note: You may need to define additional variables. Ex lluserNum is 5., then ue is 15 e 1 2+3 4 +5 a 15) HM Save C Reset MMATLAB Documentation Your Solution 1 function summedValue SummationWithLoop(userNun) 2 Sumation of all values from 1 to userNum unned Value M Write a while loop that assigns s unmedValue with the sun of all values from 1 to userNun Run Your Solution Code to call your function when you click Run C Reset SummationalithLoop(5Explanation / Answer
function summedValue = SummationWithLoop(userNum)
% Summation of all values from 1 to userNum
summedValue = 0;
i = 1;
% Do actions in the loop if i is less than or equal to userNum
while i<=userNum
% Add value of i to summedValue
summedValue = summedValue + i;
% Assign next value to i
i = i + 1;
end;
end;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.