没有什么改的,你就把你那个aver_score函数用我上面给你复制的这个,然后把你上面那个int score[10],换成float score[10],最后在上面写一句aver_score(score);

#include

main()

{void input(int *);

void max_min_value(int *);

void aver_score(float *);

int score[10]; //改成float score[10]

input(score);

//这里加上一句aver_score(score);

aver_score(score);

max_min_value(score);

return 0;

}

void max_min_value(int *score) //改成(float *score)形参

{int *max,*min,*p;

max=min=score;

for (p=score+1;p*max) max=p;

else if (*p*max) max=p;

else if (*p

printf(“最高分:%d,最低分:%d”,max,min);

}

//下面aver_score这个方法我已经给你改好了,你直接拷过去就行了

void aver_score(float *score){

int i,j;

float sum=0;

float average;

for (i=0;i<10;i++)

{

printf(“all count:%f\n”,score[i]);

sum+=score[i];

}

average=sum/10;

printf(“平均分:%f\n”,average);

}

//这个是你写的aver_score

void aver_score(int *score) //改成float *score

{int i;

float s,average; /*最重要的是这个float s这个变量你没有初始化,一般要是用它来存储运算结果,一定要初始化为零,否则内存块中依然保存上一次留下的垃圾值,也就是float s=0才对*/

for (i=0;i<=10;i++)

s+=score[i];

average=s/10.0;

printf(“平均分是:%f\n”,average);

}


版权声明:本文为weixin_39837124原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/weixin_39837124/article/details/111835938