I think the following code is where the mistake happens:
for (b=1;b<=c;b++) {
for (d=b;d<=c;d++) {
if (grade[b]<grade[d]) {
e = grade[b];
grade[b] = grade[d];
grade[d] = e;
}
}
}
If you change the second for-loop from: for (d=b;d<=c;d++)
to: for (d=1;d<=c;d++) it should work.
The problem with d=b is the following:
Consider the array holds the numbers: 5 1 2 3 4
Watch what happens with the number 4:
In the first iteration of the outer loop it sorts to: 5 2 3 4 1
In the second iteration of the outer loop it sorts to: 5 3 4 2 1
Now the third iteration follows and d is set to 3. And that is the problem, it starts with 4, compares 4 to 2 and doesn't make the comparison 3 < 4. If d is set to 1 the sorting starts with the first element all through the array every time. It is a bit inefficient but it should work.