栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

【c语言】实现学生成绩排名前十,并特别关注前10,某门分数低于80

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【c语言】实现学生成绩排名前十,并特别关注前10,某门分数低于80

已知共有30名学生,每名学生有数学、语文、物理化学、英语5门功课,班主任需要统计总分在前10名的同学的姓名和学号,另外特别关注这10名同学中有某门功课低于80分的同学,请编写程序实现上述功能

(1)先定义结构体
(2)降序排列
(3)输出前十

#include 
#define N 30
#define M 5
typedef struct Student{
	int sno;
	char sname[40];
	float score[M];			//类型同,放一个数组里
	float sum;
}student;     //定义含学号,数学,语文,物理,化学,英语,总分的结构体
int main(){
	void sort(student * st);
	void rank(student *st);
	student st[N];
	int i, j;
	int count;


	for( i = 0; i < N; i++)
	{
		st[i].sno = i+1;
		for( j = 0; j < i+1; j++)
			st[i].sname[j] = 'c';
		st[i].sname[j] = '';
		st[i].sum = 0;
		for(int j = 0; j < M; j++){
			st[i].score[j] =  i*10+10;
			st[i].sum += st[i].score[j];
		}
	}

	sort(st);
	rank(st);		
	

}


void sort(student *st){
	int i, j;
	student stemp;
	for(i = 0; i < N; i++)
	{
		for( j = 0; j < N - i - 1; j++)
		{
			if(st[j].sum < st[j + 1].sum)
			{
				stemp = st[j+1];
				st[j+1] = st[j];
				st[j] = stemp;
			}
		}
	}
}

void rank(student *st){			//st是已经经过降序排的学生数组
	int i, n = 0, j;
	for( i = 0; i < N - 1; i++){

		if(n == 11)
			break;
		printf("第%-2d名 学号%-5d 姓名%-30s", n+1, st[i].sno, st[i].sname);
		for(int j = 0; j < M; j++)
			if(st[i].score[j] < 80){
				printf("t需要特别关注");
				break;
			}

		printf("n");

		if( st[i].sum > st[i + 1].sum){
			n++;
		}
		
			
	}

}

```c
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/429749.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号