您的位置:首页 > 其它

请编写一个c函数,该函数给出一个字节中被置为1的位的个数

2016-10-26 13:27 316 查看
#include <stdio.h>

void fun(char ch)
{
int i;
int temp;
int count=0;

for(i=0;i<8;i++)
{
temp=(ch>>i) & 1;
if(temp == 1)
{
count++;
}
}
printf("Ch include 1!\n");
printf("%d\n",count);
}

int main()
{
char ch;
printf("Enter a ch!\n");
scanf("%c",&ch);
fun(ch);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐