-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti_array.c
More file actions
35 lines (29 loc) · 890 Bytes
/
multi_array.c
File metadata and controls
35 lines (29 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
int main() {
/* TODO: declare the 2D array grades here */
float average;
int i;
int j;
int grades [2][5]; /* defined multidimensional array */
grades[0][0] = 80;
grades[0][1] = 70;
grades[0][2] = 65;
grades[0][3] = 89;
grades[0][4] = 90;
grades[1][0] = 85;
grades[1][1] = 80;
grades[1][2] = 80;
grades[1][3] = 82;
grades[1][4] = 87;
/* TODO: complete the for loop with appropriate terminating conditions */
for (i = 0; i < 2; i++) { /* added i < 2 in order for the loop to cover both arrays defined above */
average = 0;
for (j = 0; j < 5; j++) { /* added j < 4 in order for the loop to add each grade */
average += grades[i][j];
}
/* TODO: compute the average marks for subject i */
average /= 5;
printf("The average marks obtained in subject %d is: %.2f\n", i, average);
}
return 0;
}