ADD file via upload

main
p72fupixj 1 year ago
parent 9ca477effa
commit cb7a1af61e

78
3.c

@ -0,0 +1,78 @@
#include<stdio.h>
#define N 3
struct stu_info
{
int num;
float math,physics,english,total,ave;
};
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)->ave>(stu+j+1)->ave)
{
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].total=stu[i].math+stu[i].physics+stu[i].english;
stu[i].ave=stu[i].total/3;
}
sort(stu);
for(i=0;i<N;i++)
{
printf("%d,%.1f,%.1f\n",stu[i].num,stu[i].total,stu[i].ave);
}
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…
Cancel
Save