In: Computer Science
Using Matlab do the following
Write a program that will accept a number from the user and:
I have written the relevand comments
clc;
clear;
sum = 0;
while true % loop breaks only when user enters 999
num = input("Please enter a number in between of 50 and 100. To quit Enter 999");
if num >= 50 && num <= 100 % number should be in range of (50,100)
fprintf("Given number is in the range of (50,100)\n");
sum = sum + num; % adding to sum variable if the input is in the range
elseif num == 999
break; % if 999 is entered loop breaks
else
fprintf("Error: Number not in range\n")
end
end
fprintf("Total sum of the entered inputs: %d",sum);
Code Image Snippet and Ouput Images:
Code:
Output:
Please leave a comment for any further doubts.