写一个函数返回参数值为1的个数 。如15 00001111 有4个1
2014-12-21 19:59
309 查看
#include <stdio.h> int count_one_bits(unsigned int value) { int count = 0; while(value) { if( value%2 == 1) count++; value = value/2; } printf("%d\n",count); return 0; } int main() { unsigned int n; scanf("%d",&n); count_one_bits(n); return 0; }
#include <stdio.h> int count_one_bits(unsigned int value) { int count = 0; while(value) { count ++; value = value & (value - 1) ; } printf("%d\n",count); return 0; } int main() { unsigned int n; scanf("%d",&n); count_one_bits(n); return 0; }
相关文章推荐
- 写一个函数返回参数值为1的个数 比如:15 0000 1111 4个1
- 写一个函数返回参数值为1的个数 比如: 15 00001111 4个1 程序类型: int count_one_bits(unsigned int value)
- 【c语言】写一个函数返回参数值为1的个数,求100~200之间素数,乘法口诀表
- 【c语言】写一个函数返回参数值为1的个数
- 写一个函数返回参数值为1的个数
- .写一个函数返回二进制参数值为1的个数
- 【c语言】写一个函数返回参数值为1的个数(优化)
- 写一个函数返回参数值为1的个数
- 【c语言】写一个函数返回参数值为1的个数
- 【C语言】写一个函数返回参数值为1的个数
- C语言 写一个函数返回参数值二进制为1的个数
- 写一个函数返回参数值为1的个数
- 写一个函数返回参数值为1的个数
- 【c语言】写一个函数返回参数值为1的个数(优化)
- 一个函数返回多个值
- 函数可以返回一个值,变通一下,过程也行。
- 如何让一个函数返回多个值
- 一个函数返回多个值 C#
- Flex中如何在Tree控件中指定一个自定义的label函数使其返回的标签名字为叶项目的名称的例子
- 一个简单的oracle函数返回数组的例子