求大神解决 C语言 我要求输入10个学生信息 可是输完第一个就错了
#include<stdio.h>#include<string.h>intn=10;structstudent{intnum;charname;floatscore[3...
#include<stdio.h>#include<string.h>int n=10;struct student {int num;char name;float score[3];};void stu_input(struct student stu[],int n); float average(struct student stu[],int n,int i);struct student stu_max(struct student stu[],int n);main(){struct student stu[n],max;int i;float aver[10]; printf("请输入10位学生的信息\n");stu_input(stu,n);for(i=0;i<n;i++) {aver[i]=average(stu,n,i); printf("学号:%d,平均分:%f\n",stu[i].num,aver[i]);}printf("成绩最好的学生:\n"); max=stu_max(stu,n); printf("%d %s %f %f %f",max.num,max.name,max.score[0],max.score[1],max.score[2]);}void stu_input(struct student stu[],int n){int i;for(i=0;i<n;i++)scanf("%d %s %f %f %f",&stu[i].num,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);}float average(struct student stu[],int n,int i){float aver;aver=0; {aver=stu[i].score[0]+stu[i].score[1]+stu[i].score[2];}aver/=3.0;return (aver);}struct student stu_max(struct student stu[],int n){int i;float sum[n],max;struct student summax; for(i=0;i<n;i++) {sum[0]=stu[i].score[0]+stu[i].score[1]+stu[i].score[2];}max=sum[0];summax=stu[0];for(i=1;i<n;i++) {if(max<sum[i]) {max=sum[i]; summax=stu[i];}}return(summax);}
展开
展开全部
修改好了:
#include<stdio.h>
#include<string.h>
int n=10;
struct student
{
int num;
char name[20];
float score[3];
};
void stu_input(struct student stu[],int n);
float average(struct student stu[],int n,int i);
struct student stu_max(struct student stu[],int n);
main()
{
struct student stu[n],max;
int i;
float aver[n];
printf("请输入10位学生的信息\n");
stu_input(stu,n);
for(i=0;i<n;i++)
{aver[i]=average(stu,n,i);
printf("学号:%d,平均分:%f\n",stu[i].num,aver[i]);}
printf("成绩最好的学生:\n");
max=stu_max(stu,n);
printf("%d %s %f %f %f",max.num,max.name,max.score[0],max.score[1],max.score[2]);
}
void stu_input(struct student stu[],int n)
{
int i;
for(i=0;i<n;i++)
scanf("%d %s %f %f %f",&stu[i].num,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
}
float average(struct student stu[],int n,int i)
{
float aver;
aver=0;
{aver=stu[i].score[0]+stu[i].score[1]+stu[i].score[2];}
aver/=3.0;
return (aver);
}
struct student stu_max(struct student stu[],int n)
{
int i;
float sum[n],max;
struct student summax;
for(i=0;i<n;i++)
{sum[i]=stu[i].score[0]+stu[i].score[1]+stu[i].score[2];}
max=sum[0];summax=stu[0];
for(i=0;i<n;i++)
{if(max<sum[i])
{max=sum[i];
summax=stu[i];}}
return(summax);
}
#include<stdio.h>
#include<string.h>
int n=10;
struct student
{
int num;
char name[20];
float score[3];
};
void stu_input(struct student stu[],int n);
float average(struct student stu[],int n,int i);
struct student stu_max(struct student stu[],int n);
main()
{
struct student stu[n],max;
int i;
float aver[n];
printf("请输入10位学生的信息\n");
stu_input(stu,n);
for(i=0;i<n;i++)
{aver[i]=average(stu,n,i);
printf("学号:%d,平均分:%f\n",stu[i].num,aver[i]);}
printf("成绩最好的学生:\n");
max=stu_max(stu,n);
printf("%d %s %f %f %f",max.num,max.name,max.score[0],max.score[1],max.score[2]);
}
void stu_input(struct student stu[],int n)
{
int i;
for(i=0;i<n;i++)
scanf("%d %s %f %f %f",&stu[i].num,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
}
float average(struct student stu[],int n,int i)
{
float aver;
aver=0;
{aver=stu[i].score[0]+stu[i].score[1]+stu[i].score[2];}
aver/=3.0;
return (aver);
}
struct student stu_max(struct student stu[],int n)
{
int i;
float sum[n],max;
struct student summax;
for(i=0;i<n;i++)
{sum[i]=stu[i].score[0]+stu[i].score[1]+stu[i].score[2];}
max=sum[0];summax=stu[0];
for(i=0;i<n;i++)
{if(max<sum[i])
{max=sum[i];
summax=stu[i];}}
return(summax);
}
追问
大神 能和我说下 我主要错在哪里吗
追答
仔细对比一下区别改动之处,就可以知道了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询