//按值 #include <bits/stdc++.h> using namespace std; int sum(int a){ if(a<=2){ return 1; }else{ return sum(a-1)+sum(a-2); } } int main(){ int x,c,d; cin>>c; x=sum(c); cout<<x; return 0; } //地址 #include <bits/stdc++.h> using namespace std; int sum(int &a){ int b,c; b=a-1; c=a-2; if(a<=2){ return 1; }else{ return sum(b)+sum(c); } } int main(){ int x,a; cin>>a; x=sum(a); cout<<x; return 0; } //指针 #include <bits/stdc++.h> using namespace std; int sum(int *a){ int b=*a-1,c=*a-2; if(*a<=2){ return 1; }else{ return sum(&b)+sum(&c); } } int main(){ int x,a; cin>>a; x=sum(&a); cout<<x; return 0; }
标签:std,cout,--,sum,namespace,斐波,int,那契 From: https://www.cnblogs.com/fushuxuan/p/17795490.html