c语言高手进

2024-11-25 09:47:47
推荐回答(1个)
回答1:

//冒泡算法的问题,这个可以,编译通过了!
#include "stdio.h"
typedef struct
{
char num[13];
float math,computer,english,avr,sum;
} student;

void main()
{
student A[10];
for(int i=0;i<10;i++)
{
printf("print student numble,score of math , computer and english\n");
scanf("%s%f%f%f",&A[i].num,&A[i].math,&A[i].computer,&A[i].english);
A[i].sum=A[i].math+A[i].computer+A[i].english;
A[i].avr=A[i].sum/3;
}
student B;

for(i=9;i>=0;i--)
for(int j=0;j {
if(A[j].avr {
B=A[j];
A[j]=A[j+1];
A[j+1]=B;
}
}
for(i=0;i<10;i++)
{
printf("%d",i+1);
printf("\t%s",A[i].num);
printf("\t%.1f",A[i].math);
printf("\t%.1f",A[i].english);
printf("\t%.1f",A[i].computer);
printf("\t%.2f",A[i].sum);
printf("\t%.2f",A[i].avr);
printf("\n");
}
}