user-0 提问: 求助

回复:
user: user-1
content: #include<stdio.h> #include<string.h>  struct MyStruct {     int num;     char name[20];     int s1;     int s2;     int s3;     int s4;     int s5;     int pj; }s[1000];  #if 0 struct student {     int num;     char name[20];     int s1;     int s2;     int s3;     int s4;     int s5;     int pj; }e[1000]; #endif  void main() {     int i, n, m,a,b=0,c[1000],d;     printf("请输入班级人数\n");     scanf_s("%d", &n);     for (i = 0; i < n; i++)     {         printf("请输入第%d位学生的学号\n", i + 1);         scanf_s("%d", &s[i].num);         printf("请输入第%d位学生的姓名\n", i + 1);         scanf_s("%s", s[i].name, 10);         printf("请输入第%d位学生的第一科成绩\n", i + 1);         scanf_s("%d", &s[i].s1);         printf("请输入第%d位学生的第二科成绩\n", i + 1);         scanf_s("%d", &s[i].s2);         printf("请输入第%d位学生的第三科成绩\n", i + 1);         scanf_s("%d", &s[i].s3);         printf("请输入第%d位学生的第四科成绩\n", i + 1);         scanf_s("%d", &s[i].s4);         printf("请输入第%d位学生的第五科成绩\n", i + 1);         scanf_s("%d", &s[i].s5);         s[i].pj = (s[i].s1 + s[i].s2 + s[i].s3 + s[i].s4 + s[i].s5) / 5;         printf("___________________________________________\n");     }     struct MyStruct tmp;     for (i = 0; i < n; i++)     {         //d = n;         d = i;         for (a = 0; a < n; a++)         {             if (s[i].pj > s[a].pj)             {                 d = a;                 //d--;             }         }          if (d != i) {             tmp = s[d];             s[d] = s[i];             s[i] = tmp;         } #if 0         e[d].num = s[i].num;         strcpy_s(e[d].name,10, s[i].name,10);         e[d].s1 = s[i].s1;         e[d].s2 = s[i].s2;         e[d].s3 = s[i].s3;         e[d].s4 = s[i].s4;         e[d].s5 = s[i].s5;         e[d].pj = s[i].pj; #endif     }     printf("请输入你想输出的排名\n(注意排名请不要大于班级人数)\n");     scanf_s("%d", &m);     if (m >= n)         m = n-1;     //printf("第%d名\n学号：%d\n姓名：%s\n第一科成绩：%d\n第二科成绩：%d\n第三科成绩：%d\n第四科成绩：%d\n第五科成绩：%d\n平均成绩：%d", m, e[m].num, e[m].name, e[m].s1, e[m].s2, e[m].s3, e[m].s4, e[m].s5, e[m].pj);     printf("第%d名\n学号：%d\n姓名：%s\n第一科成绩：%d\n第二科成绩：%d\n第三科成绩：%d\n第四科成绩：%d\n第五科成绩：%d\n平均成绩：%d", m, s[m].num, s[m].name, s[m].s1, s[m].s2, s[m].s3, s[m].s4, s[m].s5, s[m].pj); } 供参考～  结构体类型声明一次就好了，可以定义多个变量； 选择排序有点问题，对比代码找一下问题吧

user: user-2
content: 既然私信我了，就写个代码代参考  #include <stdio.h> #include <stdlib.h> #include <string.h>  struct student1 {     int num;     char name[20];     char birth[10];     int yw;     int sx;     int yy;     int wl;     int hx;     float aver; };  struct student2 {     int ranking;     int num;     char name[20];     float aver; };  void InputStudent(struct student1 *arr, int n); void SortArr(struct student1 *arr, struct student2 *arr2, int n);  int main() {     int m=0, n=0, i;     struct student1 sarr1[1000] = {0};     struct student2 sarr2[1000] = {0};      printf("请输入班级人数：\n");     scanf("%d", &n);     InputStudent(sarr1, n);     SortArr(sarr1, sarr2, n);     while (1)     {         printf("请输入排名号(0退出)：\n");         scanf("%d", &m);         if (m == 0)             break;         if (m<0 || m>n)         {             printf("输入错误，请重新输入：\n");         }         else         {             for (i=0; i<n; i++)             {                 if (m == sarr2[i].ranking)                 {                     printf("学号\t姓名\t出生日期\t成绩一\t成绩二\t成绩三\t成绩四\t成绩五\t平均分\n");                       printf("%d\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%.2f\n",sarr1[i].num, sarr1[i].name,                            sarr1[i].birth, sarr1[i].yw, sarr1[i].sx, sarr1[i].yy, sarr1[i].wl,                            sarr1[i].hx, sarr1[i].aver);                     break;                 }             }         }     }       return 0; }  void InputStudent(struct student1 *arr, int n) {     int i;     for (i=0; i<n; i++)     {         printf("请输入第%d位学生的学号、姓名、出生日期、成绩一、成绩二、成绩三、 成绩四、成绩五：\n", i+1);         scanf("%d%s%s%d%d%d%d%d",&arr[i].num, arr[i].name, arr[i].birth,               &arr[i].yw, &arr[i].sx, &arr[i].yy, &arr[i].wl, &arr[i].hx);         arr[i].aver = (arr[i].yw + arr[i].sx + arr[i].yy + arr[i].wl + arr[i].hx) / 5.0;      } }   void SortArr(struct student1 *arr, struct student2 *arr1, int n) {     struct student1 temp = {0};     int i, j;     for (i=0; i<n-1; i++)     {         for (j=0; j<n-i; j++)         {             if (arr[j].aver < arr[j+1].aver)             {                 temp = arr[j];                 arr[j] = arr[j+1];                 arr[j+1] = temp;             }         }     }     for (i=0; i<n; i++)     {         arr1[i].ranking = i+1;         arr1[i].num = arr[i].num;         strcpy(arr1[i].name, arr[i].name);         arr1[i].aver = arr[i].aver;     } }