Matlab question A list of 30 exam scores is 31 70 92 5 47 88
Matlab question:
A list of 30 exam scores is: 31, 70, 92, 5, 47, 88, 81, 73, 51, 76, 80, 90, 55, 23, 43, 98, 36, 87, 22, 61, 19, 69, 26, 82, 89, 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 fprintf to display the results)
Solution
score=[31 70 92 5 47 88 81 73 51 76 80 90 55 23 43 98 36 87 22 61 19 69 26 82 89 99 71 59 49 64];
stu=0;
stu1=0;
stu2=0;
stu3=0;
stu4=0;
for i=1:1:30
if(score(i)>=0&&score(i)<=19)
stu=stu+1;
end
if(score(i)>=20&&score(i)<=39)
stu1=stu1+1;
end
if(score(i)>=40&&score(i)<=59)
stu2=stu2+1;
end
if(score(i)>=60&&score(i)<=79)
stu3=stu3+1;
end
if(score(i)>=80&&score(i)<=100)
stu4=stu4+1
end
end
fprintf(\'Grades between 0 and 19: %d\',stu);
fprintf(\'Grades between 20 and 39: %d\',stu1);
fprintf(\'Grades between 40 and 59: %d\',stu2);
fprintf(\'Grades between 60 and 79: %d\',stu3);
fprintf(\'Grades between 80 and 100: %d\',stu4);
