代码如下:

#include<stdio.h> #include<string.h>

typedef struct Student{ int sno; char name[10]; char sex; int age; }Student;

typedef struct Table{ Student stu[1000]; int num; }Table;

int main(){ Table table; int n; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d %s %c %d",&table.stu[i].sno,&table.stu[i].name,&table.stu[i].sex,&table.stu[i].age); } scanf("%d %s %c %d",&table.stu[n].sno,&table.stu[n].name,&table.stu[n].sex,&table.stu[n].age); n++; for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ if(table.stu[i].sno>table.stu[j].sno){ Student temp=table.stu[i]; table.stu[i]=table.stu[j]; table.stu[j]=temp; } } } for(int i=0;i<n;i++){ printf("%d %s %c %d\n",table.stu[i].sno,table.stu[i].name,table.stu[i].sex,table.stu[i].age); } return 0;

现有一个学生表学生信息包括:学号、姓名、性别、年龄表中包含n个学生数据已经按照学号从小到大排序现在输入一个新的学生信息然后将它插入到表中的对应位置保证表中数据仍然按照升序排列打印插入以后的数据表。结构体定义如下:typedef struct Studentint sno;char name10;char sex;int age;Student;typedef struct TableStudent

原文地址: https://www.cveoy.top/t/topic/fDEF 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录