kai


私信TA

用户名:dotcpp0593017

访问量:559

签 名:

等  级
排  名 4882
经  验 1554
参赛次数 0
文章发表 18
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

TA的其他文章

/*

有10个学生,每个学生的数据包括学号、姓名、3门课程的成绩,
从键盘输人10个学生数据,要求输出3门课程总平均成绩,
以及最高分的学生的数据(包括学号、姓名、3门课程成绩、平均分数)。

*/
#include<stdio.h>
#include<stdlib.h>
struct student{
	int num;
	char name[30];
	int score[3];
	float avg;
};
int sort(struct student *stu);
int main()
{
	struct student students[3];
	for(int i = 0;i<3;i++)
	{
		scanf("%d %s %d %d %d",&students[i].num,students[i].name,
		&students[i].score[0],&students[i].score[1],&students[i].score[2]);
		students[i].avg = (students[i].score[0]+students[i].score[1]+students[i].score[2])/3;
	}
	int maxi = sort(students);
	
	printf("%d %s %d %d %d %lf\n", students[maxi].num, students[maxi].name, students[maxi].score[0], students[maxi].score[1], students[maxi].score[2],
		(students[maxi].score[0] + students[maxi].score[1] + students[maxi].score[2]) / 3.0);
}
//选排 
int sort(struct student *stu)
{
	int i,j,min,k,tnum,ts1,ts2,ts3;
	for(i = 0;i<3;i++)
	{
		min = stu[i].avg;
		for(j = i+1;j<3;j++)
		{
			if(min<stu[j].avg)
			{
				min = stu[j].avg;
				k = j;
			}
		}
	}
	return k;
}


 

0.0分

0 人评分

  评论区