View Code of Problem 82

#include<stdio.h>
#include<stdlib.h>
struct stu{
	char a[10];
	char b[10];
	float s1;
	float s2;
	float s3;
}; 
int main()
{
	struct stu student[10];
	int i,j,n;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s%s%f%f%f",&student[i].a,&student[i].b,&student[i].s1,&student[i].s2,&student[i].s3);
	}
	int sum1=0,sum2=0,sum3=0;
	for(i=0;i<n;i++)
	{
		sum1=sum1+student[i].s1+student[i].s2+student[i].s3;
		printf("%.0f ",sum1/3);
	}
	int j,h=student[0].s1+student[0].s2+student[0].s3;
	for(i=1;i<n;i++)
	{
		if (h<(student[i].s1+student[i].s2+student[i].s3))
		   {
			 j=i;
			h=student[i].s1+student[i].s2+student[i].s3); }
	}
//	printf("%.0f %.0f %.0f\n",avg1,avg2,avg3);
    printf("%s %s %.0f %.0f %.0f\n",student[j].a,student[j].b,student[j].s1,student[j].s2,student[j].s3);
    return 0;
	
	
}
/*
Main.c: In function 'main':
Main.c:17:3: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[10]' [-Wformat=]
   scanf("%s%s%f%f%f",&student[i].a,&student[i].b,&student[i].s1,&student[i].s2,&student[i].s3);
   ^
Main.c:17:3: warning: format '%s' expects argument of type 'char *', but argument 3 has type 'char (*)[10]' [-Wformat=]
Main.c:23:3: warning: format '%f' expects argument of type 'double', but argument 2 has type 'int' [-Wformat=]
   printf("%.0f ",sum1/3);
   ^
Main.c:25:6: error: redeclaration of 'j' with no linkage
  int j,h=student[0].s1+student[0].s2+student[0].s3;
      ^
Main.c:13:8: note: previous declaration of 'j' was here
  int i,j,n;
        ^
Main.c:31:47: error: expected ';' before ')' token
    h=student[i].s1+student[i].s2+student[i].s3); }
                                               ^
Main.c:31:47: error: expected statement before ')' token
Main.c:19:20: warning: unused variable 'sum3' [-Wunused-variable]
  int sum1=0,sum2=0,sum3=0;
                    ^
Main.c:19:13: warning: unused variable 'sum2' [-Wunused-variable]
  int sum1=0,sum2=0,sum3=0;
             ^
*/

Double click to view unformatted code.


Back to problem 82