In: Computer Science
Using MATLAB
A list of 30 test scores is: 31, 70, 92, 5, 47, 88, 73, 51, 76, 80, 90, 55, 23, 43, 98, 36, 87, 22, 61, 19, 69, 26, 82, 99, 71, 59, 49, 64
Write a computer program that determines how many grades are between 0 and 19, between 20 and 39, between 40 and 59, between 60 and 79, and between 80 and 100. The results are displayed in the following form:
Grades between 0 and 19, 2 students
Grades between 20 and 39, 4 students
Grades between 40 and 59, 6 students
and so on (Hint: use the command fprintf to display the results).
Ans
code:-
list=[31, 70, 92, 5, 47, 88, 73, 51, 76, 80, 90, 55, 23, 43, 98, 36, 87, 22, 61, 19, 69, 26, 82, 99, 71, 59, 49, 64];
c1=0;c2=0;c3=0;c4=0;c5=0;
%iterate and check conditions
for i=1:length(list)
if(list(i)<=19)
c1=c1+1;
elseif(list(i)>=20&list(i)<=39)
c2=c2+1;
elseif(list(i)>=40&list(i)<=59)
c3=c3+1;
elseif(list(i)>=60&list(i)<=79)
c4=c4+1;
elseif(list(i)>=80&list(i)<=100)
c5=c5+1;
end
end
%print result
fprintf('Grades between 0 and 19, %d students\n',c1);
fprintf('Grades between 20 and 39, %d students\n',c2);
fprintf('Grades between 40 and 59, %d students\n',c3);
fprintf('Grades between 60 and 79, %d students\n',c4);
fprintf('Grades between 80 and 100, %d students\n',c5);
If any doubts ask in the comments.