View Code of Problem 82

#include<stdio.h>
struct stu{
	int id;
	char name[20];
	int grade1;
	int grade2;
	int grade3;
}student[10000];
int main(){
	int n,i,ave1=0,ave2=0,ave3=0;
	int max,a,t;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d%s%d%d%d",&student[i].id,&student[i].name,\
		&student[i].grade1,&student[i].grade2,&student[i].grade3);	
	for(i = 0;i<n;i++){
		ave1+=student[i].grade1;
		ave2+=student[i].grade2;
		ave3+=student[i].grade3;
	}
	printf("%d %d %d\n",ave1/n,ave2/n,ave3/n);
	max = student[0].grade1+student[0].grade2+student[0].grade3;
	a = 0;
	for(i=1;i<n;i++){
		t = student[i].grade1+student[i].grade2+student[i].grade3;
		if(t>max){
			max = t;
			a = i;
		}
	}
	printf("%d %s %d %d %d",student[a].id,student[a].name,\
	student[a].grade1,student[a].grade2,student[a].grade3);
	return 0;
}

Double click to view unformatted code.


Back to problem 82