find an average of ten random numbers input by the user in matlab

main.m
% Define a variable to hold the sum
sum = 0;

% Loop ten times to get user input and add it to the sum
for i = 1:10
    % Get input from the user
    num = input('Enter a number: ');
    % Add the input to the sum
    sum = sum + num;
end

% Calculate and display the average
average = sum / 10;
fprintf('The average of the numbers is %f\n', average);
352 chars
15 lines

related categories

gistlibby LogSnag