返回题解分享
讨论 / 题解分享/ 帖子详情

奇偶统计 - 题解

//循环判断 循环结束条件 cin 为 0 时
while ( cin >> num ) { //(cin >> num) != 0 (error) cin >> 是一个bool值
if ( num == 0 ) {
// evenNumber++; 0作为结束符对待 不计入其中
break;
}
if ( num % 2 == 0 ) {
evenNumber++;
}else {
oddNum += num;
}
}

//输出结果
cout << evenNumber << endl;
cout << oddNum << endl;
return 0;
0 回复 0 转发 0 喜欢 3 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!