You are viewing a single comment's thread. Return to all comments →
I did this with backward iteration and without your most inner If:
for(int i = grades.Length-1; i >=0; i--)
if(grades[i] >= 38 && grades[i] % 5 >2)
grades[i] = grades[i] + (5 - (grades[i] % 5));
What's the point of the backwards iteration? It practically won't make any difference.
Yes it will! it will make the array go back wards and solution will be saved and appear in LIFO.
It is a stack implementation.
in your solution what happen if grade[i] = 67
them grades[i] % 5 = 7
5-7 = -2
67 -2 = 65
No, it will not pass the second condition of the if statement. Because 67 % 5 = 2 not 7.
As @keickhoff1 pointed out 67 remains 67.
please correct yourself
and please do learn how to use modulus operator