As a disclaimer, this is not homework. It is from an independent program which my instructor has given to anyone wanting additional MATLAB practice.
So here is my code
function summedValue = SummationWithLoop(userNum) % Summation of all values from 1 to userNum
summedValue = 0; i = 1; % Write a while loop that assigns summedValue with the
% sum of all values from 1 to userNum
while i<userNum summedValue=userNum+(userNum-i) i=i+1
end
What i want to do is input a value (say 5) and get the sum of (5+4+3+2+1=15) The pseudo code would look like the initial question above. Can you help correct this code I attempted to write?
Best Answer