#include#includeint i;struct Student{ char name[100]; //char mingzi[100]; int age; //int nianling; float score; //char fenshu;};void shuru(struct Student * p1, int a){ for (i = 0; i < a; i++) { printf("请输入第 %d 位学生的信息。\n", i+1); printf("name = "); scanf("%s", p1.name); printf("age = "); scanf("%d", &p1.age); printf("score = "); scanf("%f", &p1.score); }}void paixu(struct Student * p2, int n){ struct Student t; for (i = 0; i < n - 1; i++) { for (int j = 0; j < n - 1 - i; j++) { if (p2[j] .score < p2[j + 1].score) // 大于是升序 小于是降序 { t = p2[j]; p2[j] = p2[j + 1]; p2[j + 1] = t; } } }}void shuchu(struct Student * p3, int b) { for (i = 0; i < b; i++) { printf("第 %d 名学生的信息为: \n", i+1); printf(" 姓名: = %s\n", p3.name); printf(" 年龄: = %d\n", p3.age); printf(" 分数: = %.2f\n", p3.score); }} int main(void){ int n; struct Student * p; printf("请输入学生的个数: n = "); scanf("%d", &n); printf("\n"); p = (struct Student *)malloc(n * sizeof(struct Student)); shuru(p, n); paixu(p, n); printf("\n\n"); shuchu(p, n); return 0;} |