休息一天,随便写写,但还是坚持发
#define _CRT_SECURE_NO_WARNINGS 1
#include <string.h>
#include <stdio.h>
int main()
{
int a, b, c;
a = 5;
c = ++a;
b = ++c, c++, ++a, a++;
b += a++ + c;
printf("a = %d b = %d c = %d\n", a, b, c);
return 0;
}
//int count_num_1(int n)//不适用负数
int count_num_1(unsigned int n)//无符号数
{
int count = 0;
while (n)
{
if ((n % 2) == 1)
{
count++;
}
n /= 2;
}
return count;
}
int count_num_1(int n)
{
int i = 0;
int count = 0;
for (i = 0; i < 32; i++)
{
if ((n >> 1)&1 == 1)
{
count++;
}
}
return count;
}
int count_num_1(int n)
{
int count = 0;
while (n)
{
n = n & (n - 1);
count++;
}
return count;
}
int main()
{
int num = 0;
scanf("%d", &num);
int n = count_num_1(num);
printf("%d\n", n);
return 0;
}
标签:count,return,19,++,int,num,printf
From: https://blog.51cto.com/u_16182079/6779749