ai怎么把文字变成路径:C语言写代码分别将某班10个同学英语和计算机两门课程的成绩从高到低排序,并求各门课的平均成绩

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/03 02:20:48
分别将某班10个同学英语和计算机两门课程的成绩从高到低排序,并求各门课的平均成绩(保留一位小数)
英语:85,70,92,57,80,44,63,88,65,47。
计算机:74,82,60,56,76,68,73,85,69,72。
要求:(1)建立排序函数,名为sort,函数返回值是平均成绩;
(2)sort函数放置到main( )函数后;
(3)main( )函数中对两个成绩组初始化,调用,输出。

#include<stdio.h>
#include<math.h>
#define N 10

float sort(int *score);

void main(){
int eng[N]={85,70,92,57,80,44,63,88,65,47};
int math[N]={74,82,60,56,76,68,73,85,69,72};
printf("average of english is:%0.1f\n",sort(eng));
printf("average of math is:%0.1f\n",sort(math));
}

/*冒泡法排序*/
float sort(int *score)
{int i,j,temp=0,total=0;

for(j=1;j<N;j++)/*j表示第几趟*/

{

for(i=1;i<=N-j;i++)

{

if(score[i]>score[i+1])
{
temp=score[i];
score[i]=score[i+1];
score[i+1]=temp;
}

}

}

for(i=1;i<N;i++) total+=score[i];
return(total/N);
}