#include<stdio.h>
struct student{
int num;
char name[10];
int score;
};
int main()
{
int i,n,sum=0,x;
struct student s[10];
printf("Input n:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Input the number,name,score of the %d student:",i+1);
scanf("%d%s%d",&s[i].num,s[i].name,&s[i].score);
sum+=s[i].score;
}
x=sum/n;
printf("The average score is:%.2f",x);
return 0;
}
为啥输出平均分是0.00啊,哪一步出问题了吗
#include<stdio.h>
struct student{
int num;
char name[10];
int score;
};
int main()
{
int i,n,sum=0,x;
struct student s[10];
printf("Input n:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Input the number,name,score of the %d student:",i+1);
scanf("%d%s%d",&s[i].num,s[i].name,&s[i].score);
sum+=s[i].score;
}
x=sum/n;
printf("The average score is:%.2f",x);
return 0;
}