+ 3

Array Sorting?

Is there any codes or post that have a similar problem like this? i'll have it as a reference Store 10 valid grades of students in an array in the range of 60-100. The program should also determine the number of students having scores n each of the following range: Poor: 60-74 Fair: 75-80 Good: 81-85 Very Good: 86-90 Outstanding: 91-100 Output should look like this: Enter grade of student 1: 74 Enter grade of student 2: 76 Enter grade of student 3: 81 -tally of grades- Poor: 1 fair: 1 Good: 1 tnx! ❤️

22nd Sep 2020, 12:56 PM
Lia Costa ✨
Lia Costa ✨ - avatar
2 Answers
+ 1
Sorting is a very time consuming operation. In your case, you do not need to overcomplicate your code. It would be a better solution just to iterate through your array and count how many grades of each category there is using if. In this case complexity will be O(n).
22nd Sep 2020, 1:06 PM
Aleksandrs
Aleksandrs - avatar
+ 1
Just take inputs into a array and check values within a range and increment corresponding grade. Finally display... No need to sort i think.
22nd Sep 2020, 1:25 PM
Jayakrishna 🇮🇳