1 | #include "func_fibonnacci.h" |
---|
2 | #include "func_io.h" |
---|
3 | |
---|
4 | int fibonnacci(int x) |
---|
5 | { |
---|
6 | int i; |
---|
7 | int xn = 0; |
---|
8 | int xn_1 = 1; |
---|
9 | int xn_2 = 0; |
---|
10 | |
---|
11 | for (i=0;i<=x;i++) |
---|
12 | { |
---|
13 | xn = xn_1 + xn_2; |
---|
14 | xn_2 = xn_1; |
---|
15 | xn_1 = xn; |
---|
16 | } |
---|
17 | |
---|
18 | return xn; |
---|
19 | } |
---|
20 | |
---|
21 | //------------------------------------------------------------------------- |
---|
22 | //-----[ Test ]------------------------------------------------------------ |
---|
23 | //------------------------------------------------------------------------- |
---|
24 | |
---|
25 | void test_fibonnacci (int x) |
---|
26 | { |
---|
27 | int x_max = 43; |
---|
28 | int wait [x_max+1]; |
---|
29 | |
---|
30 | wait [ 0] = 1; // 1 |
---|
31 | wait [ 1] = 2; // 2 |
---|
32 | wait [ 2] = 3; // 3 |
---|
33 | wait [ 3] = 5; // 5 |
---|
34 | wait [ 4] = 8; // 8 |
---|
35 | wait [ 5] = 13; // d |
---|
36 | wait [ 6] = 21; // 15 |
---|
37 | wait [ 7] = 34; // 22 |
---|
38 | wait [ 8] = 55; // 37 |
---|
39 | wait [ 9] = 89; // 59 |
---|
40 | wait [10] = 144; // 90 |
---|
41 | wait [11] = 233; // e9 |
---|
42 | wait [12] = 377; // 179 |
---|
43 | wait [13] = 610; // 262 |
---|
44 | wait [14] = 987; // 3db |
---|
45 | wait [15] = 1597; // 63d |
---|
46 | wait [16] = 2584; // a18 |
---|
47 | wait [17] = 4181; // 1055 |
---|
48 | wait [18] = 6765; // 1a6d |
---|
49 | wait [19] = 10946; // 2ac2 |
---|
50 | wait [20] = 17711; // 452f |
---|
51 | wait [21] = 28657; // 6ff1 |
---|
52 | wait [22] = 46368; // b520 |
---|
53 | wait [23] = 75025; // 12511 |
---|
54 | wait [24] = 121393; // 1da31 |
---|
55 | wait [25] = 196418; // 2ff42 |
---|
56 | wait [26] = 317811; // 4d973 |
---|
57 | wait [27] = 514229; // 7d8b5 |
---|
58 | wait [28] = 832040; // cb228 |
---|
59 | wait [29] = 1346269; // 148add |
---|
60 | wait [30] = 2178309; // 213d05 |
---|
61 | wait [31] = 3524578; // 35c7e2 |
---|
62 | wait [32] = 5702887; // 5704e7 |
---|
63 | wait [33] = 9227465; // 8cccc9 |
---|
64 | wait [34] = 14930352; // e3d1b0 |
---|
65 | wait [35] = 24157817; // 1709e79 |
---|
66 | wait [36] = 39088169; // 2547029 |
---|
67 | wait [37] = 63245986; // 3c50ea2 |
---|
68 | wait [38] = 102334155; // 6197ecb |
---|
69 | wait [39] = 165580141; // 9de8d6d |
---|
70 | wait [40] = 267914296; // ff80c38 |
---|
71 | wait [41] = 433494437; // 19d699a5 |
---|
72 | wait [42] = 701408733; // 29cea5dd |
---|
73 | wait [43] = 1134903170; // 43a53f82 |
---|
74 | |
---|
75 | for (int i = 0; i <= ((x<x_max)?x:x_max); i ++) |
---|
76 | if (fibonnacci (i) != wait[i]) quit(i+1); |
---|
77 | } |
---|