C语言 求平均数

East

编辑个性签名

正式会员
注册
2020/04/24
消息
267
金粒
359.99金粒
C:
#include <stdio.h>

int main()
{//求平均数
    double a=0;                //数的和
    int b=0;                //数的数量
    double c;                //数
    printf("输入数值,-1结束\n");
    scanf("%lf",&c);
    while(c!=-1){
        a+=c;
        b++;
        printf("输入数值\n");
        scanf("%lf",&c);
    };
    printf("结果为%f",a/b);
    
    return 0;
}
 

在线会员

  • mrchen
  • 秋瑾瑾
  • 波旬W
  • 超越时间之影
  • 秽墨丶
  • Nico6719
  • 幻.
  • 追风_
  • kevin2025
  • mc_xiaoQAQ_
  • bast_l
  • zgxggc
  • wwjzyq
  • 七六
  • Unreal.
  • Carver
  • Alasion
  • 代桑official
  • Zenith
  • MiaoXiaoliu
...和 6 更多。
后退
顶部 底部