输入一个四位的正整数,判断它的各个位上是否存在偶数(c++)

我们要去输入一个四位正整数然后去判断输出

个位的话我们是要去%10,百位就要%100%10

下面是代码

#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    if (n % 10 % 2 == 0 || n / 10 % 10 % 2 == 0 ||
        n / 100 % 10 % 2 == 0 || n / 1000 % 2 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/endofdestruction/article/details/132172809