0
Two Dimensional Array in C, Can anyone please explain the for Loop?
3 Answers
+ 1
Read from inner to outer loop.
For fixed i=0 you loop over j as usual in an array. Here you sum up all grades written in grades[0]. So for j=0 you access grades[0][0], for j=1 grades[0][1] and so on up to grades[0][4].
The j-loop has finished, so the i-loop gets incremented and it all starts again with i=1, accessing all grades[1][j] entries.
At the end of the i-loop you calculate the average for the specific i.
average holds the sum up to this line, so to get the average, you have to devide by the number of entries which are 5 here.
0
Hi Matthias, Thanks for your response. In Line 23 of code i.e. "average=0", I didn't got it, why it's done?
0
To reset the variable for the next run, because you calculate a new average (for grades[1])