parent
75989e5068
commit
260b67b66b
@ -0,0 +1,78 @@
|
||||
#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;
|
||||
}
|
Loading…
Reference in new issue