Q:

Write a script that will:  generate a random integer in the inclusive range from 2 to 5  loop that many times to o prompt the user for a number o print the sum of the numbers entered so far with one decimal place

0

 Write a script that will:

 generate a random integer in the inclusive range from 2 to 5

 loop that many times to

o prompt the user for a number

o print the sum of the numbers entered so far with one 

decimal place

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Ch5Ex7.m

% Generate a random integer and loop to prompt the

% user for that many numbers and print the running sums

ranint = randi([2,5]);

runsum = 0;

for i = 1:ranint

 num = input('Please enter a number: ');

 runsum = runsum + num;

 fprintf('The sum so far is %.1f\n', runsum)

end

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now