学习

一个人走
程序代码:#include <stdio.h>
#include <stdlib.h>
int main(void) {
int x = 9999;
int count = func(x);
printf("count : %d\n", count);
system("pause");
return 0;
}
int func(int x) {
int count = 0;
while(x) {
x % 2 == 0 ? count : count++;
x >>= 1;
}
return count;
}这个程序也能完成同样的功能 x % 2 == 0 ? count : count++; 这段代码可以改为 if(x % 2) { count++; }