I have to create a 2 dimensional array (5X4 (int type)) which can hold 4 exam scores for each of 5 students.Here is my code:
#include<stdio.h>
int main(void)
{
int numstu = 5;
double studentscore[numstu][5];
double score1, score2, score3, score4;
int i, z;
double avgstu;
double avgexam = 0;
double sum = 0;
for(i = 0; i < 5; i++){
printf("Please input 4 exam scores for student %d: ", i+1);
scanf("%lf%lf%lf%lf", &score1, &score2, &score3, &score4);
studentscore[i][0] = score1;
studentscore[i][1] = score2;
studentscore[i][2] = score3;
studentscore[i][3] = score4;
avgstu = (score1 + score2 + score3 + score4) / 4.0;
studentscore[i][4] = avgstu;
printf("Average score for student %d is: %lf\n", i+1, avgstu);
}
for(z = 0; z < 4; z++){
for(i = 0; i < 5; i++){
avgexam += studentscore[i][z] / 5;
}
printf("Average exam %d is: %lf\n", z+1, avgexam);
avgexam = 0;
}
return 0;
}
Now I a asked to write a function that will output the entry data appropriately labeled, for example:
Student Data
Exam 1 Exam 2 Exam 3 Exam 4
1 75 82 66 87
2 69 59 72 77
3 66 87 77 62
4 80 57 91 93
5 94 86 88 96
Can someone please give me a hint of how to do that? I have no idea how to start.
