Complete the following beginner C Program to calculate and compare students grad
ID: 3833507 • Letter: C
Question
Complete the following beginner C Program to calculate and compare students grades on an exam:
Below is the formatting required.
An exam has 2 sections (named Section A and Section B) each containing 4 questions worth 20 points each. Students must answer 5 questions in total with at least 2 from Section A and 2 from Section B. If more questions than required are answered, then the first ones are counted and the later ones are disregarded. Unanswered questions are indicated by a grade of 0 Write a C program to read in each student's id number (a 4 digit value) followed by 8 scores (with each score being in the range 0-20 inclusive). An id number of 0 indicates the end of input. You may assume the correct number of input values are entered; however, if any score is out-of-range you are to replace it in your calculations (and the output table) with a 0. Here is some sample input data: 1234 10 15 0 0 20 8 17 0 3200 109 7 20 2 24 0 10 9122 5 6 10 0 19 5 3 14 6022 000 20 0 15 0 6 1077 20 18 00 20 19 16 0 Input to your program must come from standard input via redirection on the comman line (as discussed in class; see the sample run below). You will echo print each student's id and scores along with printing out their result and all appropriate comments. Output, including all labels and spacings, must appear exactly as it appears in the sample run below. Depending on the data entered your program should also print out 0 or more of the following comments in the order and manner that is shown in the sample run: Score incorrect More than 5 Less than 5 Too many from A Too many from B You also should report the total number of students who took the exam along with the average result.Explanation / Answer
#include<stdio.h>
void comments(int secA,int secB)
{
int total=secA+secB;
if(secA>3)
printf("Too many from A");
else if(secB>3)
printf("Too many from B");
else if(total>5)
printf("More than 5");
else if(total<5)
printf("Less than 5");
}
int main()
{
int i,j,n,incorrect=0,secA=0,secB=0,total=0,id,students=0,noofstudents;
int arr[10][9];
scanf("%d",&id);
int x=0;
int y=0;
while(id)
{
arr[x][y]=id;
for(i=1;i<9;i++)
{
scanf("%d",&n);
arr[x][i]=n;
}
students++;
scanf("%d",&id);
x++;
y=0;
}
noofstudents=students;
printf(" id Section A Section B Result Comments ");
i=0;
while(i<noofstudents-1)
{
printf("%d ",arr[i][0]);
for(j=1;j<9;j++)
{
n=arr[i][j];
if(n>20||n<0)
{
n=0;
incorrect=1;
}
printf("%2d ",n);
if(n!=0&&j<5)
{
secA++;
if(secA<=3)
total=total+n;
}
else if(n!=0&&j>=5)
{
secB++;
if(secA>=3&&secB<=2)
total=total+n;
if(secA<3&&secB<=3)
total=total+n;
}
}
printf(" %2d",total);
if(incorrect==1)
printf("Score incorrect");
comments(secA,secB);
i++;
}
}