鱼C论坛

 找回密码
 立即注册
查看: 2320|回复: 3

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

[复制链接]
发表于 2014-8-9 17:16:28 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include<stdio.h>
void test(int b[10]);
void main()
{
        int score[10]={2, 4, 6, 8,10,12,14,16,18,20};
        test(score);

}
void score(int b[10])
{
        int i=0,s=0;
        float z;
        for(;i<10;i++)
        {
                s=s+b[i];
                z=s/10;
       
        }       
        printf("%d\n",s);
        printf("%f\n",z);

       
}

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2014-8-9 17:23:00 | 显示全部楼层
本帖最后由 oggplay 于 2014-8-9 17:26 编辑

把Z移出循环
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2014-8-9 17:26:24 | 显示全部楼层
  1. #include<stdio.h>
  2. void test(int * b);
  3. //void test(int b[10]);
  4. void main()
  5. {
  6.         int score[10]={2, 4, 6, 8,10,12,14,16,18,20};
  7.         test(score);
  8.        
  9. }
  10. //void score(int b[10])
  11. void test(int * b)
  12. {
  13.         int i=0,s=0;
  14.         float z;
  15.         for(;i<10;i++)
  16.         {
  17.                 s=s + b[i];
  18.                 //z=s/10;  
  19.         }   
  20.         z = s/10;
  21.         printf("%d\n",s);
  22.         printf("%f\n",z);
  23.        
  24.        
  25. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2014-8-9 18:04:02 | 显示全部楼层
大神么都解答了,。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-11 12:43

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表