输入五名学生四门课程的成绩,统计每个学生的总分,及确定每个学生的名次,用函数做.谢谢.
来源:百度知道 编辑:UC知道 时间:2024/06/20 19:10:24
#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 = st