题库 C++/C语言题库 题目列表 下面代码采用递推算法来计算斐波那契数列f(n)=f(n-1)+...
单选题

下面代码采用递推算法来计算斐波那契数列f(n)=f(n-1)+f(n-2),则横线上应填写( )。

1 int fib(int n) {
2  if (n == 0 || n == 1) 
3   return n; 
4
5  int f1 = 0; 
6  int f2 = 1; 
7  int result = 0; 
8  for (int i = 2; i <= n; i++) { 
9   ________________________________ // 在此处填入代码 
10  } 
11  return result; 
12 }
A.
1 result = f1 + f2; 
2 f1 = f2; 
3 f2 = result;
B.

1 result += f1 + f2

2 f1 = f2

3 f2 = result;

C.
1 result += f1 + f2; 
2 f2 = result; 
3 f1 = f2;
D.
1 result = f1 + f2; 
2 f2 = result; 
3 f1 = f2;
题目信息
2024年 四级 选择题
-
正确率
0
评论
26
点击