最后的综合练习里,我做完平均分后一输出就报错,不输出就不会报错,其他的正常输出,输出平均分就报错 输出平均分用的是float,看了别人的照着打再输出还是会报错,反正不输出平均分就不报错气死我了,一直找不到问题 hello.c: In function 'main': hello.c:6:19: warning: implicit declaration of function 'zongfen' [-Wimplicit-function-declaration] printf("%d\n",zongfen(score)); ^~~~~~~ hello.c:7:19: warning: implicit declaration of function 'zuigaof' [-Wimplicit-function-declaration] printf("%d\n",zuigaof(score)); ^~~~~~~ hello.c:8:19: warning: implicit declaration of function 'zuidif' [-Wimplicit-function-declaration] printf("%d\n",zuidif(score)); ^~~~~~ hello.c:10:19: warning: implicit declaration of function 'pingjunf' [-Wimplicit-function-declaration] printf("%f\n",pingjunf(score)); ^~~~~~~~ hello.c:10:14: warning: format '%f' expects argument of type 'double', but argument 2 has type 'int' [-Wformat=] printf("%f\n",pingjunf(score)); ^ hello.c: At top level: hello.c:47:7: error: conflicting types for 'pingjunf' float pingjunf(int score[]) ^~~~~~~~ hello.c:10:19: note: previous implicit declaration of 'pingjunf' was here printf("%f\n",pingjunf(score));
以下是代码:
#include <stdio.h>
#include <string.h>
int main()
{
int score[10]={67,98,75,63,82,79,81,91,66,84};
printf("%d\n",zongfen(score));
printf("%d\n",zuigaof(score));
printf("%d\n",zuidif(score));
printf("%f\n",pingjunf(score));
return 0;
}
int zongfen(int score[]){
int i;
int bb=0;
for(i=0;i<=9;i++){
bb+=score[i];
}
return bb;
}
int zuigaof(int score[])
{
int i;
int bb=0;
for(i=0;i<=9;i++)
{
if(score[i]>bb){
bb=score[i];
}
}
return bb;
}
int zuidif(int score[])
{
int i;
int bb;
for(i=0;i<=9;i++)
{
if(score[i]<bb){
bb=score[i];
}
}
return bb;
}
float pingjunf(int score[])
{
float a;
a=(float)zongfen(score)/10;
return a;
}