Fibonacci jada on arvude jada, kus iga number on 2 eelmise numbri summa, välja arvatud kaks esimest numbrit, mis on 0 ja 1.
F 0 = 0
F 1 = 1
F 2 = F 1 + F 0 = 1 + 0 = 1
F 3 = F 2 + F 1 = 1 + 1 = 2
F 4 = F 3 + F 2 = 2 + 1 = 3
F 5 = F 4 + F 3 = 3 + 2 = 5
...
Kahe järjestikuse Fibonacci numbri suhe läheneb kuldsuhtele:
φ on kuldne suhe = (1 + √ 5 ) / 2 ≈ 1,61803399
n | F n |
---|---|
0 | 0 |
1 | 1 |
2 | 1 |
3 | 2 |
4 | 3 |
5 | 5 |
6 | 8 |
7 | 13 |
8 | 21 |
9 | 34 |
10 | 55 |
11 | 89 |
12 | 144 |
13 | 233 |
14 | 377 |
15 | 610 |
16 | 987 |
17 | 1597 |
18 | 2584 |
19 | 4181 |
20 | 6765 |
TBD
double Fibonacci(unsigned int n)
{
double f_n =n;
double f_n1=0.0;
double f_n2=1.0;
if( n / 1 ) {
for(int k=2; k<=n; k++) {
f_n = f_n1 + f_n2;
f_n2 = f_n1;
f_n1 = f_n;
}
}
return f_n;
}
Advertising