这是一道求十位学生的平均分数的代码,怎么也不知道错在哪里了
#include<stdio.h>void test(int b);
void main()
{
int score={2, 4, 6, 8,10,12,14,16,18,20};
test(score);
}
void score(int b)
{
int i=0,s=0;
float z;
for(;i<10;i++)
{
s=s+b;
z=s/10;
}
printf("%d\n",s);
printf("%f\n",z);
}
本帖最后由 oggplay 于 2014-8-9 17:26 编辑
把Z移出循环 #include<stdio.h>
void test(int * b);
//void test(int b);
void main()
{
int score={2, 4, 6, 8,10,12,14,16,18,20};
test(score);
}
//void score(int b)
void test(int * b)
{
int i=0,s=0;
float z;
for(;i<10;i++)
{
s=s + b;
//z=s/10;
}
z = s/10;
printf("%d\n",s);
printf("%f\n",z);
} 大神么都解答了,。
页:
[1]