您的位置:首页 > 其它

计算9999的二进制中含有多少个1

2013-06-19 11:18 459 查看
// 求数字的二进制含有多少个1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
int func(int num)
{
int countx = 0;
while (num)
{
countx ++;
num = num&(num-1);
}
return countx;
}
int _tmain(int argc, _TCHAR* argv[])
{
int num=9999;
int count=func(9999);
printf("%d",count);
getchar();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: