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

奇偶统计 - 题解

#include <iostream>
using namespace std;
int main() {
    int a,sum=0,sum2=0;
    while (true)
    {
        cin >> a;
        if (a == 0) {
            break;
        }
        if (a % 2 == 0) {
            sum++;
        }
        else {
            sum2+=a;
        }
    }
    cout << sum << endl << sum2;
    return 0;
}
一行+顺便判断,没了
0 回复 0 转发 0 喜欢 3 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!