输入5个学生的姓名,学号和5门课成绩,用C语言结构体数组实现:

我是学C的...谢谢啊...拜托了...

你把数据改改就可以了书上的
#include<stdio.h>
#define N 10
struct student
{
char num[6];
char name[8];
char sex[2]
float score[3];
float avr;
}
stu[N];
void main()
{int i,j,maxi;
float sum,max,average;
for(i=0;i<N;i++)
{printf("input scores of student %d:\n",i+1);
printf("No.:");
scanf("%s",stu[i].num);
printf("name:");
scanf("%s",stu[i].name);
printf("sex:");
scanf("%s",stu[i].sex);
for(j=0;j<3;j++)
{printf("score %d:",j+1);
scanf("%f",&stu[i].score[j]);
}}
average=0;
max=0;
maxi=0;
for(i=0;i<N;i++)
{sum=0;
for(j=0;j<3;j++)
sum+=stu[i].score[j];
stu[i].avr=sum/3.0;
average+=stu[i].avr;
if(sum>max)
{max=sum;
maxi=i;
}}
average/=N;
printf("No. name sex score1 score2 score3 average\n");
for(i=0;i<N;i++)
{printf("%5s%10s",stu[i].num,stu[i].name);
for(j=0;j<3;j++)
printf("%9.2f",stu[i].score[i]);
printf(" %8.2f\n",stu[i].avr);
}
printf("average=%5.2f\n",average);
printf("The highest score is: student %s,%s.\n",stu[maxi].num,stu[maxi].name);
printf("His score are:%6.2f,%6.2f,%6.2f,average:%5.2f.\n",stu[maxi].score[0],stu[maxi].score[1],stu[maxi].score[2],stu[maxi].avr);
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2019-07-21
你把数据改改就可以了书上的
#include<stdio.h>
#define
N
10
struct
student
{
char
num[6];
char
name[8];
char
sex[2]
float
score[3];
float
avr;
}
stu[N];
void
main()
{int
i,j,maxi;float
sum,max,average;for(i=0;i<N;i++){printf("input
scores
of
student
%d:\n",i+1);printf("No.:");scanf("%s",stu[i].num);printf("name:");scanf("%s",stu[i].name);printf("sex:");scanf("%s",stu[i].sex);for(j=0;j<3;j++){printf("score
%d:",j+1);scanf("%f",&stu[i].score[j]);}}
average=0;
max=0;
maxi=0;
for(i=0;i<N;i++)
{sum=0;for(j=0;j<3;j++)sum+=stu[i].score[j];stu[i].avr=sum/3.0;average+=stu[i].avr;if(sum>max){max=sum;maxi=i;}}
average/=N;
printf("No.
name
sex
score1
score2
score3
average\n");
for(i=0;i<N;i++)
{printf("%5s%10s",stu[i].num,stu[i].name);for(j=0;j<3;j++)printf("%9.2f",stu[i].score[i]);printf("
%8.2f\n",stu[i].avr);}
printf("average=%5.2f\n",average);
printf("The
highest
score
is:
student
%s,%s.\n",stu[maxi].num,stu[maxi].name);
printf("His
score
are:%6.2f,%6.2f,%6.2f,average:%5.2f.\n",stu[maxi].score[0],stu[maxi].score[1],stu[maxi].score[2],stu[maxi].avr);
}
相似回答