前言
代码
#include <iostream>
using namespace std;
int Fibonacci(int n);
int main()
{
int Result = Fibonacci(10);
cout << "输出结果: Result = "<< Result << endl;
getchar();
return 0;
}
int Fibonacci(int n)
{
int Fn;
if (n == 1 || n == 2)
Fn = 1;
else
Fn = (Fibonacci(n - 1) + Fibonacci(n - 2));
return Fn;
}
示例
//根据数列,输入10,即会输出结果55