First Program: Calculate Grade Average Description: Design a program that calcul
ID: 3722327 • Letter: F
Question
First Program: Calculate Grade Average
Description: Design a program that calculates the grade averages of two students with 4 grades each. For example, if student 1’s grades were 90, 100, 95, and 80 then the average would be 91 for that student.
Requirements:
Properly document code using the C Source Coding standards.
Use only integer values for grades.
Read grades from the keyboard input real-time for each student.
The input request should look like the below for each student (without quotes):
“Please enter Student 1 first grade: “
“Please enter Student 1 second grade: “ (on a newline)
etc
Display all grades entered per student and their grade average. The output should be as below (example only based on inputted grades) :
“Student 1 grades: 90, 100, 95, 80. Average is 91.”
“Student 2 grades: 80, 20, 60, 70. Average is 57.” (on a new line)
Explanation / Answer
#include<stdio.h>
int main() {
int i,j,a[2][4],avg,sum=0;
for(i=0;i<2;i++) {
printf("Please enter Student %d first grade: ",i+1);
scanf("%d", &a[i][0]);
printf("Please enter Student %d second grade: ",i+1);
scanf("%d", &a[i][1]);
printf("Please enter Student %d third grade: ",i+1);
scanf("%d", &a[i][2]);
printf("Please enter Student %d fourth grade: ",i+1);
scanf("%d", &a[i][3]);
}
for(i=0;i<2;i++) {
sum=0;
printf("“Student %d grades: ",i+1);
for(j=0;j<4;j++) {
sum+=a[i][j];
if(j==3) {
printf("%d. ",a[i][j]);
} else {
printf("%d, ",a[i][j]);
}
}
avg= sum/4;
printf("Average is %d ", avg);
}
}
Output:
Please enter Student 1 first grade: 90
Please enter Student 1 second grade: 100
Please enter Student 1 third grade: 95
Please enter Student 1 fourth grade: 80
Please enter Student 2 first grade: 80
Please enter Student 2 second grade: 20
Please enter Student 2 third grade: 60
Please enter Student 2 fourth grade: 70
“Student 1 grades: 90, 100, 95, 80. Average is 91
“Student 2 grades: 80, 20, 60, 70. Average is 57
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.