We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 513070d commit 816c274Copy full SHA for 816c274
src/c/FibonacciMemoization.c
@@ -0,0 +1,29 @@
1
+#include <stdio.h>
2
+
3
+#define MAX_N 100 // Define the maximum number for which you want to calculate Fibonacci
4
5
+int memo[MAX_N]; // Memoization table to store computed values
6
7
+int fibonacci_memoization(int number) {
8
+ if (number <= 1) {
9
+ return number;
10
+ }
11
+ if (memo[number] != -1) {
12
+ return memo[number];
13
14
15
+ memo[number] = fibonacci_memoization(number - 1) + fibonacci_memoization(number - 2);
16
17
+}
18
19
+int main(void) {
20
+ int test_nbr = 12;
21
22
+ // Initialize the memoization table with -1 (uncomputed)
23
+ for (int i = 0; i < MAX_N; i++) {
24
+ memo[i] = -1;
25
26
27
+ printf("memoization: %d\n", fibonacci_memoization(test_nbr));
28
+ return 0;
29
0 commit comments