数据结构学习录(一)——用顺序表将学生的成绩进行排队 C程序

数据结构学习录(一)——用顺序表将学生的成绩进行排队 C程序

输入:
N个学生的两个成绩

输出:
按两个成绩的平均成绩排序后输出

/*学生成绩从小到大排序    数组*/ 
#include<stdio.h>
#define N 3
struct student
{
	int num;                       //学号
	char name[20];            //名字
	char lengde;                //性别
	float score1;                //成绩1
	float score2;                //成绩2
	float av;                       //平均成绩
//	struct student *next;
 } ;
 
 int main ()
 {
 	void input(struct student stu[]);
 	struct student paixu(struct student stu[]);
 	struct student stu[N],*p=stu;
 	input(p);
	paixu(p);
	return 1; 
 }
 
 void input(struct student stu[])
 {
 	int i;
 	for(i=0;i<N;i++)
 	{
 		printf("请输入个学生的信息:学号,姓名,性别(f or w),2门课成绩:\n");
		scanf("%d %s %c %f %f",&stu[i].num,stu[i].name,&stu[i].lengde,&stu[i].score1,&stu[i].score2);
		stu[i].av=(stu[i].score1+stu[i].score2) /2.0;
	 }
 }
 
 struct student paixu(struct student stu[])
 {
 	struct student temp;
	int i,j;
	for(j=0;j<N;j++)
	{
		for(i=j;i<N;i++)
		{
			if(stu[i].av<stu[j].av)
			{
				temp=stu[i];
				stu[i]=stu[j];
				stu[j]=temp;
			}
		}
	}
	printf("从小到大排序后:\n");
	printf("%15s %20s %6s %6s %6s\n","学号","姓名","成绩1","成绩2","平均分");
 	for(i=0;i<N;i++)
 	{
 		printf("%15d %20s %6.2f %6.2f %6.2f\n\t",stu[i].num,stu[i].name,stu[i].lengde,stu[i].score1,stu[i].score2,stu[i].av);
 		printf("\n");
	 }
 }

  • 0
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值