#include<iostream> #include<cstdlib> using namespace std; int Fab(int n) { if(n==1) cout<<1<<endl; else if(n==2) cout<<2<<endl; else if(n==3) cout<<3<<endl; else { return Fab(n-1)+Fab(n-3); } } int main() { int n; cin>>n; if(n==1) return 0; else cout << Fab(n) << endl; system("pause"); return 0; }不知道哪里错了
CHJH明亦 2020-04-30 12:05:23 |
第一点是主函数里的if似乎没什么用;第二点是对于你的fab函数,递归下去的话并没有返回什么东西回来,只是输出了一些东西,改成“return 1;return 2;return 3;”就可以了
为什么第一头牛第一年年初不生