From ae62f75cc47eb1bda61512f3065e1fdf08fa7abf Mon Sep 17 00:00:00 2001 From: p49a3zeks <1346664542@qq.com> Date: Sun, 12 Nov 2023 22:07:10 +0800 Subject: [PATCH] Add step3 --- step3 | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 step3 diff --git a/step3 b/step3 new file mode 100644 index 0000000..4d17714 --- /dev/null +++ b/step3 @@ -0,0 +1,55 @@ +#include +struct Student +{ + int id; + float gs; + float dw; + float yy; + float sum; + float aver; +}stu[3],temp; +int main() +{ + printf(" 1.Input\n"); + printf(" 2.Output\n"); + printf(" 3.Order\n"); + printf(" 4.Quit\n"); + int i=0,j=0; + char x; + scanf("%c",&x); + switch(x){ + case 'o':printf("You are trying to Output info");break; + case 'm':printf("You are trying to Make things ordered");break; + case 'q':printf("You are about to Quit");break; + case 'i':printf("Please input info of the three students:\n"); + for(i=0;i<3;i++) + { + scanf("%d\n",&stu[i].id); + scanf("%f\n",&stu[i].gs); + scanf("%f\n",&stu[i].dw); + scanf("%f\n",&stu[i].yy); + stu[i].sum=stu[i].gs+stu[i].dw+stu[i].yy; + stu[i].aver=stu[i].sum/3; + } + for( i=0;i<3;i++)//排序操作 + { + for( j=0;j<3-i-1;j++) + { + if(stu[j].sum>stu[j+1].sum) + { + temp=*(stu+j); + *(stu+j)=*(stu+j+1); + *(stu+j+1)=temp; + } + } + } + for(i=0;i<3;i++) + { + printf("学号 %d,总成绩 %.1f,平均成绩 %.1f\n",stu[i].id,stu[i].sum,stu[i].aver); + } + break; + + default:printf("Wrong input\n");break; + } + return 0; +} \ No newline at end of file