楼主您看符不符合要求#include <stdio.h>
#include <malloc.h>
struct Student
{
int age;
char name[100];
float score;
};
int len;
struct Student *pArr;
void InputStudent();
void SortStudent();
void OutputStudent();
int main()
{
InputStudent();
SortStudent();
OutputStudent();
return 0;
}
void InputStudent()
{
printf("请输入学生个数:\n");
printf("len =");
scanf("%d", &len);
pArr = (struct Student *)malloc(len * sizeof(struct Student));
for(int i = 0; i < len; i++)
{
printf("请输入第%d个学生的信息:\n", i + 1);
printf("age =");
scanf("%d", &pArr[i].age);
printf("name =");
scanf("%s", pArr[i].name);
printf("score =");
scanf("%f", &pArr[i].score);
}
}
void SortStudent()
{
int i, j;
struct Student t;
for(i = 0; i < len; i++)
{
for(j = 0; j < len-1-j; j++)
{
if(pArr[j].score > pArr[i].score)
{
t = pArr[j];
pArr[j] = pArr[i];
pArr[i] = t;
}
}
}
}
void OutputStudent()
{
printf(" \n\n学生的信息是:\n");
for(int i = 0; i < len; i++)
{
printf("第%d个学生的信息:\n", i + 1);
printf("age = %d\n", pArr[i].age);
printf("name = %s\n", pArr[i].name);
printf("score = %f\n", pArr[i].score);
printf(" \n");
}
free(pArr);
}
|