Why do the same statements have different running results in the annotated places? Aren't the statements read sentence by sentence? Why are there exceptions to gets

CSDN Q & A 2022-01-15 02:37:36

#include<stdio.h>
#define num 1
struct stu
{int xh;
char name[20];
float yw;
float sx;
float yy;
}a[num];

struct stu1
{struct stu;
float avare;
float sum;
}a1[num];

void main()
{ int i;
for(i=0;i<num;i++)
{//printf(" Please enter a name ");
//gets(a[i].name);
printf(" Please enter the student number \n");
scanf("%d",&a[i].xh);
//printf(" Please enter a name ");
//gets(a[i].name);
printf(" Please enter the grade of three subjects \n");
scanf("%f%f%f",&a[i].yw,&a[i].sx,&a[i].yy);
}
for(i=0;i<num;i++)
{ a1[i].sum=a[i].yw+a[i].sx+a[i].yy ;
a1[i].avare=a1[i].sum/3;
}

for(i=0;i<num;i++)
{ printf(" Student number :%d\n",a[i].xh);
printf(" name :%s\n",a[i].name);
printf(" Chinese language and literature :%0.1f mathematics %0.1f English %0.1f\n",a[i].yw,a[i].sx,a[i].yy);
printf("sum:%0.1f avare=%0.1f\n",a1[i].sum,a1[i].avare);
}

}


thank
Similar articles

2022-01-15

2022-01-15