题目描述
请实现如下接口
public static int findNumberOf1( int num)
{
return 0;
} 譬如:输入5 ,5的二进制为101,输出2
输入描述:
输入一个整数
输出描述:
计算整数二进制中1的个数
示例1
输入:5
输出
复制:2
#include <iostream>
using namespace std;
//二进制中1的个数
int main1()
{
int n;
while (cin >> n)
{
int count = 0;
while (n)
{
if ((n & 1) == 1)
{
count++;
}
n >>= 1;
}
cout << count << endl;
}
system("pause");
return 0;
}