输入10个学生5门课的成绩,分别用函数求: (1)每个学生平均分; (2)每门课的平均分; (3)找出最高的

2024-12-29 03:05:44
推荐回答(3个)
回答1:

程序代码 
#include  
int m=0,n=0;/*定义全局变量m,n*/ 
float average (float score[][6],int i)/* 求每个学生平均分*/ 
{ int j; 
float ave=0,sum=0;; 
for (j=1;j<6;++j) 
sum+=score[i][j]; 
ave=sum/5; 
return ave; 

float perave (float score[][6],int j)/*求每门课程平均分*/ 
{ int i; 
float aveper=0,sums=0; 
for (i=1;i<11;++i) 
sums+=score[i][j]; 
aveper=sums/10; 
return aveper; 

maxper (float score[][6])/*求最大分数所在学生和课程*/ 
{ int i,j; 
float max; 
max=score[1][1]; 
for (i=1;i<11;++i) 
for (j=1;j<6;++j) 
if (score[i][j]>max) 
{max=score[i][j]; 
m=i;n=j; 

return 0; 

main() 
{ float score[11][6]; 
int i,j; 
for (i=1;i<11;++i) 
{printf ("# %d:",i); 
scanf("%f,%f,%f,%f,%f",&score[i][1],&score[i][2],&score[i][3],&score[i][4],&score[i][5]); 

printf("\n"); 
for (i=1;i<11;++i) 
{printf ("# %d student:",i); 
printf ("%f\n",average(score,i)); 

printf("\n"); 
for (i=1;i<6;++i) 
{printf ("# %d lesson:",i); 
printf ("%f\n",perave(score,i)); 

printf("\n"); 
maxper(score); 
printf ("Max:Line:%d Row:%d\n",m,n); 
system("pause"); 
}

回答2:

double ave, max, min, total;
max = min = total = a[0];
for(int i = 1; i < 10; i ++ )
{
if(a[i] < min)
min = a[i];
else if(a[i] > max )
max = a[i];
total += a[i];

}
ave = total/10;

回答3:

直接用公式 排序