您的位置:首页 > 产品设计 > UI/UE

Fibonacci Sequence(斐波那契数列递归)

2018-02-19 20:56 190 查看
1、question:find The nth number offibonacci sequence    In mathematics, the Fibonaccinumbers are the numbers in the following integer sequence, calledthe Fibonacci         sequence, and characterized by the fact that everynumber after the first two is the sum of the two preceding ones:
     1 1 2 3 5 8 13 21 34 55 89 144.....
2、code:
#include<iostream>
#include<cstdio>
using namespace std;
int fib(int a)
{
if(a==0) return 0;
if(a==1) return 1;
else
{
return fib(a-1)+fib(a-2);
}
}
int n;
int main()
{
cin>>n;
cout<<fib(n);
return 0;

}
3、running
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: