当前位置:网站首页>c语言结构体中的冒泡排序
c语言结构体中的冒泡排序
2022-08-03 04:26:00 【BSP初级小学僧】
题目:使用结构体以及函数,首先录入学生信息,依据学生成绩,对学生相关信息进行排序。
#include <stdio.h>
#include <string.h>
struct stu_informa
{
int id;
char name[20];
int sore;
};
void struct_input(struct stu_informa stu[],int n)
{
int i;
for(i=0;i<n;i++)
{
printf("请输入第%d个学生信息(id、name、sore):\n",i);
scanf("%d",&stu[i].id);
getchar();
gets(stu[i].name);
scanf("%d",&stu[i].sore);
getchar();
}
printf("\n");
}
void struct_print(struct stu_informa stu[],int n)
{
int i;
for(i=0;i<n;i++)
{
printf("\n");
printf("stu[%d].id=%d\n",i,stu[i].id);
printf("stu[%d].name=%s\n",i,stu[i].name);
printf("stu[%d].sore=%d\n",i,stu[i].sore);
}
}
void struct_paixu(struct stu_informa stu[],int n)
{
int i,j;
struct stu_informa temp;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1-i;j++)
{
if(stu[j].sore>stu[j+1].sore)
{
temp=stu[j];
stu[j]=stu[j+1];
stu[j+1]=temp;
}
}
}
}
void test(void)
{
struct stu_informa stu[3];
struct_input(stu,3);
struct_paixu(stu,3);
struct_print(stu,3);
}
int main()
{
test();
return 0;
} 运行结果:

边栏推荐
猜你喜欢

多肽介导PEG磷脂——靶向功能材料之DSPE-PEG-RGD/TAT/NGR/APRPG

Can Oracle EMCC be installed independently?Or does it have to be installed on the database server?

数商云供应链集成系统开发方案:多行业集成平台管理自动化

Test drive: project management module - curd development project

【Harmony OS】【ARK UI】Date 基本操作

path development介绍

MySQL 入门:Case 语句很好用

StarRocks 7 月社区动态

【Harmony OS】【ARK UI】轻量级数据存储

RequestContextHolder
随机推荐
【Harmony OS】【ARK UI】轻量级数据存储
path development介绍
DC-4靶场搭建及渗透实战详细过程(DC靶场系列)
TCP相关面试常问
工程制图第九章作业
阿里面试官:聊聊如何格式化Instant
肖sir___面试就业课程____性能测试
Browser listens for tab closing
工程制图点的投影练习
WinForm的控件二次开发
DC-6靶场下载及渗透实战详细过程(DC靶场系列)
工程制图-齿轮
TCP 和UDP 的详细介绍
Dialog manager in the fourth chapter: the dialog message loop
Redis缓存雪崩、缓存穿透、缓存击穿
【软件工程之美 - 专栏笔记】35 | 版本发布:软件上线只是新的开始
Assembly answers
电子设备行业智能供应链系统:打破传统供应链壁垒,提升电子设备企业管理效能
MySQL【约束】
数字化时代,企业如何建立自身的云平台与商业模式的选择?