Part I- 2 Dimensional Arrays Write a C program called finalgrades.c. Your progra
ID: 3696557 • Letter: P
Question
Part I- 2 Dimensional Arrays Write a C program called finalgrades.c. Your program should declare a 2-dimensional array with 5 rows and 4 columns (you should use named constants so these values can be changed). Your array will represent the exam scores for a student. The first three columns will hold the scores for three exams which will be entered by the user. The fourth column will contain the average of the exam scores which your program should calculate. After all of the scores have been entered and the averages have been calculated, your program should output a result table with row and column labels like in the sample output below. (output continued on second page) Please enter exam #1 score for student #1: 77 Please enter exam #2 score for student #1: 88 Please enter exam #3 score for student #1: 99 Please enter exam #1 score for student #2: 67 Please enter exam #2 score for student #2: 68 Please enter exam #3 score for student #2 : 87 Please enter exam #1 score for student #3 : 75 Please enter exam #2 score for student #3: 67 Please enter exam #3 score for student #3: 88 Please enter exam #1 score for student #4 : 99 Please enter exam #2 score for student #4 : 98 Please enter exam #3 score for student #4 : 100Explanation / Answer
float exam_marks[5][4];
int score=0;
int average=0;
int i=0,j=0;
for(i=0;i<5;i++)
{
average = 0;
for(j=0;j<3;j++)
{
printf(" Please Enter the exam #%d score for student #%d:",j+1,j+1);
scanf("%d",&score);
exam_marks[i][j]=score;
average = average + exam_marks[i][j]; // calculate average for each row
}
exam_marks[i][3] = average/3;
}
/****************Display Final Score****************/
printf(" FINAL SCORE ");
printf(" 1 2 3 AVG ");
for(i=0;i<5;i++)
{
printf("#%d",i+1);
for(j=0;j<4;j++)
{
printf(" %.2f",exam_marks[i][j]);
}
printf(" ");
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.