View Code of Problem 82

#include <stdio.h>
int main(){
  typedef struct{
   char num[10];
   char name[10];
   float score1;
   float score2;
   float score3;
  }student;
  int n,i;
  scanf("%d",&n);
  student s[100];
  float sum1=0,sum2=0,sum3=0;
  float avge1,avge2,avge3;
  for(i=0;i<n;i++){
    scanf("%s%s%f%f%f",&s[i].num,&s[i].name,&s[i].score1,&s[i].score2,&s[i].score3);
  }
  for(i=0;i<n;i++){
    sum1+=s[i].score1;
    sum2+=s[i].score2;
    sum3+=s[i].score3;
  }
    avge1=sum1/n;
    avge2=sum2/n;
    avge3=sum3/n;
  printf("%.0f %.0f %.0f\n",avge1,avge2,avge3);
  float a[100];
  for(i=0;i<n;i++){
    a[i] = s[i].score1+s[i].score2+s[i].score3;
    
  }
  int j=0;
  for(i=1;i<n;i++){
    if(a[i]>a[0]){
      max = a[i];
      j=i;
    
      }
  }
  printf("%s %s %.0f %.0f %.0f",s[j].num,s[j].name,s[j].score1,s[j].score2,s[j].score3);

return 0;
}
/*
Main.c: In function 'main':
Main.c:16:5: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[10]' [-Wformat=]
     scanf("%s%s%f%f%f",&s[i].num,&s[i].name,&s[i].score1,&s[i].score2,&s[i].score3);
     ^
Main.c:16:5: warning: format '%s' expects argument of type 'char *', but argument 3 has type 'char (*)[10]' [-Wformat=]
Main.c:35:7: error: 'max' undeclared (first use in this function)
       max = a[i];
       ^
Main.c:35:7: note: each undeclared identifier is reported only once for each function it appears in
*/

Double click to view unformatted code.


Back to problem 82