③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;
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库C语言笔试题答案(8)在线全文阅读。
相关推荐: