#include<stdio.h>
#define N 3
struct Student
{
char id[13];
int score[3];
int sum;
float aver;
};
void input(struct Student stu0[],int count);
void sum_and_aver(struct Student stu1[],int count);
void sort(struct Student stu2[],int count);
void output(struct Student stu3[],int count);
int main(void)
{
struct Student stu[N];
input(stu,N);
sum_and_aver(stu,N);
sort(stu,N);
output(stu,N);
}
void input(struct Student stu0[],int count)
{
int i;
printf("请输入 %d 个同学的学号以及数学、英语、计算机成绩:\n",N);
printf("学号 数学 英语 计算机\n");
for(i=0;i<N;i++)
{
printf("请输入第 %d个同学各项信息:\n",i+1);
scanf("%s%d%d%d",stu0[i].id,&stu0[i].score[0],&stu0[i].score[1]
,&stu0[i].score[2]);
}
}
void sum_and_aver(struct Student stu1[],int count)
{
int i,j;
for(i=0;i<count;i++)
{
stu1[i].sum=0;
for(j=0;j<3;j++)
stu1[i].sum+=stu1[i].score[j];
stu1[i].aver=(float)stu1[i].sum/3;
}
}
void sort(struct Student stu2[],int count)
{
int i,j;
struct Student temp;
for(i=1;i<=count-1;i++)
for(j=1;j<=count-i;j++)
if(stu2[j-1].sum<stu2[j].sum)
{
temp=stu2[j-1];
stu2[j-1]=stu2[j];
stu2[j]=temp;
}
}
void output(struct Student stu3[],int count)
{
int i;
printf("%-14s%-7s%-7s%-7s%-8s%-7s\n","学号",
"数学","英语","计算机","总分","平均分");
for(i=0;i<count;i++)
printf("-14s%-7s%-7s%-7s%-5s%-6.1f\n",stu3[i].id,
stu3[i].score[0],stu3[i].score[1],stu3[i].score[2],
stu3[i].sum,stu3[i].aver);
}
//devc++ 4.9.9.2 运行通过
#define N 3
struct Student
{
char id[13];
int score[3];
int sum;
float aver;
};
void input(struct Student stu0[],int count);
void sum_and_aver(struct Student stu1[],int count);
void sort(struct Student stu2[],int count);
void output(struct Student stu3[],int count);
int main(void)
{
struct Student stu[N];
input(stu,N);
sum_and_aver(stu,N);
sort(stu,N);
output(stu,N);
}
void input(struct Student stu0[],int count)
{
int i;
printf("请输入 %d 个同学的学号以及数学、英语、计算机成绩:\n",N);
printf("学号 数学 英语 计算机\n");
for(i=0;i<N;i++)
{
printf("请输入第 %d个同学各项信息:\n",i+1);
scanf("%s%d%d%d",stu0[i].id,&stu0[i].score[0],&stu0[i].score[1]
,&stu0[i].score[2]);
}
}
void sum_and_aver(struct Student stu1[],int count)
{
int i,j;
for(i=0;i<count;i++)
{
stu1[i].sum=0;
for(j=0;j<3;j++)
stu1[i].sum+=stu1[i].score[j];
stu1[i].aver=(float)stu1[i].sum/3;
}
}
void sort(struct Student stu2[],int count)
{
int i,j;
struct Student temp;
for(i=1;i<=count-1;i++)
for(j=1;j<=count-i;j++)
if(stu2[j-1].sum<stu2[j].sum)
{
temp=stu2[j-1];
stu2[j-1]=stu2[j];
stu2[j]=temp;
}
}
void output(struct Student stu3[],int count)
{
int i;
printf("%-14s%-7s%-7s%-7s%-8s%-7s\n","学号",
"数学","英语","计算机","总分","平均分");
for(i=0;i<count;i++)
printf("-14s%-7s%-7s%-7s%-5s%-6.1f\n",stu3[i].id,
stu3[i].score[0],stu3[i].score[1],stu3[i].score[2],
stu3[i].sum,stu3[i].aver);
}
//devc++ 4.9.9.2 运行通过
雨水冲不进窗来,在玻璃上痛哭。但它至少奋斗过。