回复 9楼 wang155423
b版的意思是把4楼给的函数里的a都换成x,结合你的题中例子或许你会更好理解一点,可能会有头绪。
回复 11楼 小赵q1
可是还是没有头绪啊
程序代码:#include<stdio.h>
#include<math.h>
int f(int a)
{
int c;
for(c=0; a; a >>= 1) c += a & (a >> 1) & 1;
return c;
}
int main()
{
int n=0;
int i=0;
printf("please input the data_");
scanf("%d",&n);
for(i;i<pow(2,n);++i)
{
if(i>0)
{
printf(",");
}
printf("%d",f(i));
}
return 0;
}

程序代码:#include<stdio.h>
int f(int x)
{
int c;
for(x &= x >> 1, c = 0; x; x >>= 1) c += x & 1;
return c;
}
int main()
{
int m, i;
while(printf("Input m[1-30]:"), scanf("%d", &m), m < 1 || m > 30);
for(i = 0; i < 1 << m; printf("%d ", f(i++)));
return 0;
}
