Fibonacci Sequence(斐波那契数列递推)
1、question:find The nth number offibonacci sequence
In mathematics, the Fibonacci numbers 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 a[10005];
int fibonacci(int n)
{
a[0]=0;
a[1]=1;
for(int i=2;i<=n;i++)
{
a[i]=a[i-1]+a[i-2];
}
return a[n];
}
int n;
int main()
{
cin>>n;
cout<<fibonacci(n);
}
3、running