struct stu
{
char name[20];
long number;
float score[4];
};
struct stu student[10];
void input(struct stu arr[],int n)
{
int i,j;
char temp[30];
for (i=0;i<n;i++)
{
gets(arr[i].name);
gets(temp);
arr[i].number=atol(temp);
for(j=0;j<3;j++)
{
gets(temp);
arr[i].score[j]=atoi(temp);
}
}
}
void aver(struct stu arr[],int n)
{
int i,j;
for(i=0;i<n;i++)
{
arr[i].score[3]=0;
for(j=0;j<3;j++)
{
arr[i].score[3]=arr[i].score[3]+arr[i].score[j];
arr[i].score[3]=arr[i].score[3]/3;
}
}
}
/*void order(struct stu arr[],int n)
{
struct stu temp;
int i,j;
for(i=0;i<n-1;i++)
for(j=0;j<n-1;j++)
if(arr[j].score[3]>arr[j+1].score[3])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}*/
void output(struct stu arr[],int n)
{
int i,j;
for(i=0;i<n;i++)
{
printf("%10s%8ld",arr[i].name,arr[i].number);
for(j=0;j<4;j++)
printf("%7.1f",arr[i].score[j]);
printf("\n");
}
}
main()
{
input(student,4);
aver(student,4);
//order(student,4);
output(student,4);
}
//è¿éorderæ¯å泡æåºä½ ä¸è¦å°±å¯ä»¥å é¤å¯¹ç¨åºæ²¡æå½±åç!
温馨提示:答案为网友推荐,仅供参考