HackerLand University has the following grading policy:
- Every Student receives a
gradein the inclusive range from0to100. - Any
gradeless than40is a failing grade.
Sam is a professor at the university and likes to round each student's grade according to these rules:
- If the difference between the
gradeand the next multiple of5is less than3, roundgradeup to the next multiple of5. - If the value of
gradeis less than38, no rounding occurs as the results will still be a failing grade.
grade = 84round to85(85 - 84 is less than 3)grade = 29do not round (result is less than 40)grade = 57do not round (60 - 57 is 3 or higher)
Given the initial value of grade for each of Sam's n students, write code to automate the rounding process.
Complete the function gradingStudents in the editor below.
gradingStudents has the following parameter(s):
int grades[n]: the grades before rounding
int[n]: the grades after rounding as appropriate
The first line contains a single integer, n, the number of students. Each line i of the n subsequent lines contains a single integer, grades[i].
1 <= n <= 600 <= grades[i] <= 100
4
73
67
38
3375
67
40
33| ID | Original Grade | Final Grade | | -- - -------------- | ----------- | | 1 | 73 | 75 | | 2 | 67 | 67 | | 3 | 38 | 40 | | 4 | 33 | 33 |
- Student
1received a73, and the next multiple of5from73is75. Since75 - 73 < 3, the student's grade is rounded to75. - Student
2received a67, and the next multiple of5from67is70. Since70 - 67 = 3, the grade will not be modified and the student's final grade is67. - Student
3received a38, and the next multiple of5from38is40. Since40 - 38 < 3, the student's grade will be rounded to40. - Student
4received a grade below33, so the grade will not be modified and the student's final grade is33.