该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
//学生管理系统
# include
# include
//定义学生信息结构体
struct student
{
char name[50];
float score;
int age;
};
//学生信息输入系统
void import(struct student * pArr, int num)
{
int i;
for(i=0; i
{
printf("请输入第%d个学生姓名:", i+1);
scanf("%s", pArr[i].name);
printf("请输入第%d个学生分数:", i+1);
scanf("%f", &pArr[i].score);
printf("请输入第%d个学生年龄:", i+1);
scanf("%d", &pArr[i].age);
printf("\n");
}
}
//冒泡排序
void BubbleSort(struct student * pArr, int num)
{
int i, j;
struct student k;
for(i=0; i
{
for(j=0; j
{
if(pArr[j].score > pArr[j+1].score)
{
k = pArr[j];
pArr[j] = pArr[j+1];
pArr[j+1] = k;
}
}
}
}
//学生信息输出
void export(struct student * pArr, int num)
{
int i;
for(i=0; i
{
printf("学生姓名:%s\n", pArr[i].name);
printf("学生分数:%f\n", pArr[i].score);
printf("学生年龄:%d\n", pArr[i].age);
printf("\n");
}
}
//主函数
int main(void)
{
int num;
struct student * pArr;
printf("请输入学生人数:\n");
printf("num = ");
scanf("%d", &num);
printf("\n");
pArr = (struct student *)malloc(num * sizeof(struct student));
import(pArr, num);
BubbleSort(pArr, num);
printf("\n\n\n");
printf("按照学生分数升序排列:\n");
export(pArr, num);
return 0;
}
@雪无音在窗边