///////////////////////////////////////
/* */
/*通過autorun_inf */
/* */
///////////////////////////////////////
# include & ltstdio.h & gt
結構學生
{
int號;//學生編號
字符名稱[10];
浮動數學、英語、計算機;//三門課的成績
雙總計;//總分
雙avr//平均成績
};
結構學生stu[50];//聲明壹個結構數組變量
struct學生輸入();
void顯示(struct student stud[],int count);
void sort(struct student stud[],int count);
void main()
{
int計數;
char ch
ch = ' y
Printf("請按以下格式輸入學生信息(可用制表符對齊):");
printf(" \ n ");
count = 0;
while ((ch=='y') || (ch=='Y '))
{
stu[計數]= input();//調用信息錄入函數
count++;
printf(" \ n是否要繼續?(按Y繼續,其余結束)”);
scanf(" %c ",& ampch);
}
printf(" \ n最高分數:");
sort(斯圖,計數);//調用排序函數
顯示(stu,1);//調用顯示信息函數
}
結構學生輸入()//輸入信息函數
{
指導學生學習;
printf(" \ n學生編號\ tname \ tMath \英語\ t計算機\ n ");
scanf("%d%s%f%f%f ",& amp學生編號,學生姓名。學生數學。學生英語。studn .計算機);
studn . total = studn . math+studn . English+studn . computer;
studn . AVR = studn . total/3.0;
返回studn
}
void Display(struct study[],int count)//顯示信息函數
{
int I;
printf(" \ n學生ID \姓名\ t數學\ t英語\ t計算機\ t總成績\ t平均成績");
printf(" \ n ");
for(I = 0;我& lt數數;i++)
{
printf("%d ",stud[i].否);
printf("\t%s ",stud[i]。姓名);
printf("\t%.1f ",stud[i]。數學);
printf("\t%.1f ",stud[i]。英語);
printf("\t%.1f ",stud[i]。電腦);
printf("\t%.2f ",stud[i].合計);
printf("\t%.2f ",stud[i].AVR);
printf(" \ n ");
}
}
Voidsort (struct student stud [],int count)//排序函數
{
int i,j;
/*冒泡排序法*/
結構學生t;
for(I = 0;我& lt數數;i++)
for(j = 0;j & ltcount-I-1;J++) //比較元素
{
if(stud[j].avr & lt螺柱[j+1]。avr)
{
t = stud[j];
stud[j]= stud[j+1];
stud[j+1]= t;
}
}
}