查找输入整数二进制中1的个数

#include<iostream>
using namespace std;
int main()
{
    int n;
    while (cin >> n)
    {
        int count = 0;
        while (n)
        {
            if ((n & 1) == 1)
            {
                count++;
            }
            n >>= 1;
        }
        cout << count << endl;
    }
    system("pause");
    return 0;    
}

发布了81 篇原创文章 · 获赞 1 · 访问量 2741

猜你喜欢

转载自blog.csdn.net/weixin_44781382/article/details/105282590
今日推荐