③int NumberOf1_Solution3(int i) {
int count = 0;
while (i) {
++ count; i = (i - 1) & i; }
return count; }
29. 费波那其数列,1,1,2,3,5??编写程序求第十项。可以用递归,也可以用其他方
法,但要说明你选择的理由。
int main() { printf(\ printf(\ return 0; }
/* 递归算法 */ int Pheponatch(int N) { if( N == 1 || N == 2) { return 1; } else return Pheponatch( N -1 ) + Pheponatch( N -2 ); }
/* 非递归算法 */ int Pheponatch2(int N) { int x = 1, y = 1, temp; int i = 2; while(1) { temp = y; y = x + y; x = temp; i++;
}
if( i == N ) break; } return y;