大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项。
n<=39
class Solution {
public:
int Fibonacci(int n) {
if(n==0)
return 0;
if(n==1)
return 1;
int temp;
int temp1=0;
int temp2=1;
while(n>1){
temp=temp2;
temp2=temp2+temp1;
temp1=temp;
--n;
}
return temp2;
}
};