标签:style blog color os io strong 问题 div 代码
问题描述:
1 #include <iostream> 2 using namespace std; 3 4 int calc(int num) { 5 int count; 6 while(num){ 7 count++; 8 num = num & (num-1); 9 } 10 return count; 11 } 12 13 int main() { 14 cout << "input n: " << endl; 15 int n; 16 cin >> n; 17 int count = calc(n); 18 cout << "The num of 1 in " << n << " is: " << count << endl; 19 return 0; 20 }
输出:
$ ./a.exe input n: 11 The num of 1 in 11 is: 3
标签:style blog color os io strong 问题 div 代码
原文地址:http://www.cnblogs.com/dracohan/p/3943343.html