与运算判断奇偶数

#include <iostream>
using namespace std;
 
int main()
{
    int n = 1;
 
    cout << "输入一个整数: ";
    cin >> n;
 
    if ( ( n & 1 ) == 0)
        cout << n << " 为偶数。";
    else
        cout << n << " 为奇数。";
 
    return 0;
}

 

posted @ 2020-02-26 16:11  Y鱼鱼鱼Y  阅读(522)  评论(0)    收藏  举报