像风一样 发表于 2014-8-9 17:16:28

这是一道求十位学生的平均分数的代码,怎么也不知道错在哪里了

#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:23:00

本帖最后由 oggplay 于 2014-8-9 17:26 编辑

把Z移出循环

牡丹花下死做鬼 发表于 2014-8-9 17:26:24

#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);
       
       
}

Angel丶L 发表于 2014-8-9 18:04:02

大神么都解答了,。
页: [1]
查看完整版本: 这是一道求十位学生的平均分数的代码,怎么也不知道错在哪里了