You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Group18/学籍管理系统 步骤3.c

79 lines
1.4 KiB

#include<stdio.h>
#define N 3
struct stu_info
{
int num;
float math,physics,english,sum,average;
};
struct stu_info stu[N];
void sort(struct stu_info *stu)
{
int i,j;
struct stu_info tmp;
for(i=0;i<N;i++)
{
for(j=0;j<N-i-1;j++)
{
if((stu+j)->average>(stu+j+1)->average)
{
tmp = *(stu+j);
*(stu+j) = *(stu+j+1);
*(stu+j+1) = tmp;
}
}
}
return;
}
void input(void)
{
int i;
for(i=0;i<N;i++)
{
scanf("%d",&stu[i].num);
scanf("%f",&stu[i].math);
scanf("%f",&stu[i].physics);
scanf("%f",&stu[i].english);
stu[i].sum=stu[i].math+stu[i].physics+stu[i].english;
stu[i].average=stu[i].sum/3;
}
sort(stu);
for(i=0;i<N;i++)
{
printf("%d,%.1f,%.1f\n",stu[i].num,stu[i].sum,stu[i].average);
}
return;
}
int main()
{
char in;
printf(" 1.Input\n");
printf(" 2.Output\n");
printf(" 3.Order\n");
printf(" 4.Quit\n");
scanf("%c",&in);
switch(in)
{
case('i'):
printf("Please input info of the three students:\n");
input();
break;
case('o'):
printf("You are trying to Output info\n");
break;
case('m'):
printf("You are trying to Make things ordered\n");
break;
case('q'):
printf("You are about to Quit\n");
break;
default:
printf("Wrong input\n");
}
return 0;
}