write a script aveposnum that will repeat the process of pro
write a script aveposnum that will repeat the process of prompting the user for positive numbers,until the user enters a negative number. If the user enters a negative number, the script should print the average(of just the positive numbers). If no positive numbers are entered, the script should print an error message instead of the average.
Solution
MATLAB code:
clear all
close all
clc
j=1;
while 1
i=input(\'Enter the number :\');
if i>=0
x(j)=i;
j=j+1;
else
disp(\'wrong value entered\')
mean(x)
break
end
end
sample output is
Enter the number :1
Enter the number :2
Enter the number :3
Enter the number :4
Enter the number :-1
wrong value entered
ans =
2.5000
>>
