è¾å
¥äºåå¦çåé¨è¯¾ç¨çæ绩ï¼ç»è®¡æ¯ä¸ªå¦ççæ»åï¼åç¡®å®æ¯ä¸ªå¦ççå次:
#include "stdio.h"
struct student
{
int num; //å¦å·
double mark[4]; //4é¨æ绩
double erea; //æ»å
};
void fun()
{
int i,j;
double dtemp=0.0;
int itemp=0;
struct student stu[5];
//è¾å
¥æ¯ä¸ªå¦ççå¦å·ï¼ååé¨æ绩
for (i=0; i<5; i++)
{
printf("è¾å
¥ç¬¬%i个å¦ççå¦å·å4é¨æ绩\n",i+1);
scanf("%d%lf%lf%lf%lf",&stu[i].num,
&stu[i].mark[0],&stu[i].mark[1],&stu[i].mark[2],&stu[i].mark[3]);
}
//ç»è®¡æ»å
for (i=0; i<5; i++)
{
stu[i].erea = stu[i].mark[0] + stu[i].mark[1] +
stu[i].mark[2] + stu[i].mark[3];
}
//æå次
for (i=0; i<5; i++)
{
for (j=i+1; j<5; j++)
{
if (stu[i].erea < stu[j].erea)
{
dtemp = stu[i].erea; stu[i].erea = stu[j].erea; stu[j].erea = dtemp;//æ¢æ»å
itemp = stu[i].num; stu[i].num = stu[j].num; stu[j].num = itemp; //æ¢å¦å·
}
}
}
//è¾åºæåç»æåæ绩
printf("\næåç»æå¦ä¸ï¼\n");
for (i=0; i<5; i++)
{
printf("第%då å¦å·:%d æ»å:%lf å¹³ååï¼%lf\n",i+1,stu[i].num,stu[i].erea,stu[i].erea/4);
}
}
void main()
{
fun();
}
温馨提示:答案为网友推荐,仅供参考