#include <stdio.h>
#include <malloc.h>
struct Student{
char name[100];
int age;
float score;
};
void input_student(struct Student * parr, int len);
void sort(struct Student * a, int len);
void output_student(struct Student * a, int len);
int main()
{
int len;
struct Student * parr;
parr = (struct Student *)malloc(len * sizeof(struct Student));
printf("请输入学生总个数:");
scanf("%d",&len);
input_student(parr,len);
sort(parr,len);
output_student(parr, len);
return 0;
}
void input_student(struct Student * parr, int len)
{
int i;
for (i=0; i<len; i++)
{
printf("请输入第 %d 个学生的信息\n",i+1);
printf("名字:");
scanf("%s",parr[i].name);
printf("年龄:");
scanf("%d",&parr[i].age);
printf("成绩:");
scanf("%f",&parr[i].score);
}
}
void sort(struct Student * a, int len)
{
int i, j;
struct Student t;
for (i=0; i<len-1; i++)
{
for (j=0; j<len-1-i; j++)
{
if (a[j].score < a[j+1].score)
{
t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
}
}
}
void output_student(struct Student * a, int len)
{
int i;
for (i=0; i<len; i++)
{
printf("第 %d 个学生的信息:\n", i+1);
printf("名字:%s 年龄:%d 成绩:%f\n",a[i].name, a[i].age, a[i].score);
}
}
一个简单的学生成绩管理系统
最新推荐文章于 2024-06-29 13:38:55 发布