输入一批正整数(以零或负数为结束标志),求其中的奇数和。要求定义和调用输入一批正整数(
网友回答
break是直接跳出循环体,不再继续执行
将break;改成continue;
输入以0或负数结束;例如1 2 3 4 5 0 结果为9
#include
stdio.hint even(int n)
{if(n%2==0)
\x09 return 1;
else\x09 return 0;
}int main()
{\x09int n,sum=0;
\x09printf(Input integers:);
\x09do{
\x09\x09scanf(%d,&n);
\x09\x09if(even(n)==1)
\x09\x09\x09continue;
\x09\x09else
\x09\x09\x09sum=sum+n;
\x09}\x09while(n>0);\x09printf(The sum of the odd numbers is %d,sum);
\x09return 0;
}