Write a computer program that determines how many grades are between 0 and 19
5 views (last 30 days)
Show older comments
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 command fprintf to display the results)
3 Comments
Joshua Magno
on 13 Oct 2016
Edited: Joshua Magno
on 13 Oct 2016
I=[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];
a=sum(I>=0 & I<=19);
fprintf('The grades between 0 and 19 is %1.0f students.\n',a)
b=sum(I>=20 & I<=39);
fprintf('The grades between 20 and 39 is %1.0f students.\n',b)
c=sum(I>=40 & I<=59);
fprintf('The grades between 40 and 59 is %1.0f students.\n',c)
d=sum(I>=60 & I<=79);
fprintf('The grades between 60 and 79 is %1.0f students.\n',d)
e=sum(I>=80 & I<=100);
fprintf('The grades between 80 and 100 is %2.0f students.\n',e)
Answers (2)
Image Analyst
on 21 Apr 2016
Try histogram() or histcounts():
edge = [0, 19.5, 39.5,,,,,, etc.
counts = histcounts(.........
Two lines of code. One or two more if you want to use fprintf() to print results to the command window
fprintf('%d\n', cou..................
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!