#include <iostream>
using namespace std;
int F(int n) {
int f;
if (n <= 2)
f = 1;
else
f = F(n - 1) + F(n - 2);
return f;
}
int main() {
int n;
cout << "please enter n:" << endl;
cin >> n;
cout << "F(n)=" << F(n);
return 0;
}
用递归的方法编写函数求Fibonacci函数,公式为:
最新推荐文章于 2023-03-28 11:30:14 发布