题解 | #斐波那契数列#
斐波那契数列
https://www.nowcoder.com/practice/ee5d403c1172487f8c7915b3c3d924c6
#include<iostream> using namespace std; int f(int n){ if(n==1||n==2)return 1; return f(n-1)+f(n-2); } int main(){ int n; cin>>n; cout<<f(n); return 0; }
斐波那契数列
https://www.nowcoder.com/practice/ee5d403c1172487f8c7915b3c3d924c6
#include<iostream> using namespace std; int f(int n){ if(n==1||n==2)return 1; return f(n-1)+f(n-2); } int main(){ int n; cin>>n; cout<<f(n); return 0; }
相关推荐