File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -937,8 +937,8 @@ Com o objetivo de alcançar uma abrangência maior e encorajar mais pessoas a co
937
937
<tr>
938
938
<td><a href="https://pt.wikipedia.org/wiki/Sequ%C3%AAncia_de_Fibonacci">Fibonacci</a></td>
939
939
<td> <!-- C -->
940
- <a href="./CONTRIBUTING.md ">
941
- <img align="center" height="25" src="./logos/github .svg" />
940
+ <a href="./src/c/Fibonacci.c ">
941
+ <img align="center" height="25" src="./logos/c .svg" />
942
942
</a>
943
943
</td>
944
944
<td> <!-- C++ -->
Original file line number Diff line number Diff line change
1
+ #include <stdio.h>
2
+
3
+ int fibonacci_iterative (int number ) {
4
+ int last_number = 0 ;
5
+ int current_number = 1 ;
6
+
7
+ for (int index = 0 ; index < number ; ++ index ) {
8
+ int temp = current_number ;
9
+ current_number += last_number ;
10
+ last_number = temp ;
11
+ }
12
+ return last_number ;
13
+ }
14
+
15
+ int fibonacci_recursive (int number ) {
16
+ if (number == 0 ) {
17
+ return 0 ;
18
+ } else if (number == 1 ) {
19
+ return 1 ;
20
+ } else {
21
+ return fibonacci_recursive (number - 1 ) + fibonacci_recursive (number - 2 );
22
+ }
23
+ }
24
+
25
+ int main (void ) {
26
+ int test_nbr = 12 ;
27
+
28
+ printf ("iterative: %d\n" , fibonacci_iterative (test_nbr ));
29
+ printf ("recursive: %d\n" , fibonacci_recursive (test_nbr ));
30
+ return 0 ;
31
+ }
You can’t perform that action at this time.
0 commit comments