首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

这个break 用得对吗?该怎么处理

2014-01-15 
这个break 用得对吗?下面这个程序是要计算输入的奇数个数及平均数,偶数个数及平均数。输入0时终止。[解决办

这个break 用得对吗?
下面这个程序是要计算输入的奇数个数及平均数,偶数个数及平均数。输入0时终止


[解决办法]
各位,是分子为0的情况。
在(float)oddsum/oddcount, evensum/evencount中,oddcount和eventcount可能为零,
建议在打印输出前,做一次检测。
[解决办法]
if(oddcount != 0 && evencount !=0)
{
printf("There are %d odds and the average is %f;"
"and there are %d evens and the average is %d.\n",
oddcount, (float)oddsum/oddcount, evencount, evensum/evencount);
}

热点排行