新手 求指教!! 这个计算平均数的程序为什么输出结果不对
#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;
}
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;
}
...全文
相关推荐
c++数组求平均数函数
c++数组求平均数函数 c++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
求和 求平均数——C语言代码
课程的随堂作业,C语言的,用dev就能运行,萌新代码,勿喷,仅仅帮助不想写作业的朋友方便一下,反正老师也不会仔细检查的
python 求10个数的平均数实例
今天小编就为大家分享一篇python 求10个数的平均数实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
用java编写的一个简单的求平均数的程序
用java编写的求平均数的代码java编写的求平均数的代码java编写的求平均数的代码java编写的求平均数的代码
汇编语言求平均数
汇编语言求平均数,代码已通过debug调试


