新手 求指教!! 这个计算平均数的程序为什么输出结果不对

明朝一典史 明朝一典史 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include<stdio.h>
int main()
{
char answer=0;
int i=0;
double sum=0,
average=0,
value=0;
printf("this program caculates the value any number of value.\n");
for (i=0;;++i)
{
printf("\nEnter a number: ");
scanf("%lf",&value);
printf("Do you want to enter another number(Y or N): ");
getchar();
scanf("%c",&answer);
sum=sum+value;
++i;
if(answer=='n'||answer=='N')
break;
}
average=sum/i;
printf("\n\nthe average is:%.2f",average);
return 0;
}
...全文
评论 6
收藏 已收藏
分享
返回顶部
明朝一典史
C语言 70,039 成员 243,237 内容