递归求解斐波那契数列
作者:互联网
前言
代码
#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
标签:10,数列,示例,int,斐波,Fibonacci,那契,Fn 来源: https://blog.csdn.net/Vittore_Li/article/details/122763781