标签:
#include<stdio.h>
#include<string.h>
#define n 3
struct date
{
int year;
int month;
int day;
};
struct student
{
char num[6];
char name [10];
float score[3];
float avr;
char sex;
struct date bir;
} stu[n];
int main()
{
int i,j,maxi;
float sum,max,average;
for(int i=0; i<n; i++)
{
printf("input scores ofthe no.%dstudent\n",i+1);
printf("no.:");
scanf("%s",&stu[i].num);
printf("name:");
scanf("%s",stu[i].name);
getchar();
printf("sex:");
scanf("%c",&stu[i].sex);
printf("date:");
scanf("%d-%d-%d",&stu[i].bir.year,&stu[i].bir.month,&stu[i].bir.day);
for(int j=0; j<3; j++)
{
printf("score %d:",j+1);
scanf("%f",&stu[i].score[j]);
}
}
average=0;
max=0;
maxi=0;
for(int i=0; i<n; i++)
{
sum=0;
for(int j=0; j<3; j++)
sum=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 score1 score2 score3 sex date average\n");
for(int i=0; i<n; i++)
{
printf("%-5s %-10s",stu[i].num,stu[i].name);
for(int j=0; j<3; j++)
{
printf("%7.2f",stu[i].score[j]);
}
printf("%4c %d-%d-%d ",stu[i].sex,stu[i].bir.year,stu[i].bir.month,stu[i].bir.day);
printf(" %5.2f\n",stu[i].avr);
}
printf("%7.2f\n",average);
printf("the student is 学号:%s 姓名:%s 性别:%c 生日:%d-%d-%d\n",stu[maxi].num,stu[maxi].name,stu[maxi].sex,stu[maxi].bir.year,stu[maxi].bir.month,stu[maxi].bir.day);
printf("his score are %5.2f %5.2f %5.2faverage:%5.2f\n",stu[maxi].score[1],stu[maxi].score[2],stu[maxi].score[3],stu[maxi].avr);
return 0;
}
标签:
原文地址:http://www.cnblogs.com/SSYYGAM/p/4215305.html