不晓得为嘛右移不行啊,求解。
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int* countBits(int n)
{
int arr[] = {0};
for (int i = 0; i <= n; i++)
{
int j = i;
int val = 0;
for (;j; )
{
if (j & 1)
{
val++;
}
j >> 1;
}
arr[i] = val;
}
int* p = arr;
return p;
}
int main()
{
int n = 0;
printf("请输入n的值:");
scanf("%d", &n);
int* arr = countBits(n);
for (int i = 0; i <= n; i++)
{
printf("%d ", arr[i]);
}
return 0;
}