We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8756cf6 commit 5d789ecCopy full SHA for 5d789ec
Recursion/17 fibbonacci using memoization.c
@@ -24,17 +24,17 @@ int mfib(int n)
24
{
25
if (n<=1)
26
27
- F[n]=n;
+ F[n]=n; // in function F of n simply return the value of the n if n is less then 1;
28
return n;
29
}
30
else
31
32
- if (F[n-2]==-1)
33
- F[n-2]=mfib(n-2);
34
- if (F[n-1]==-1);
35
- F[n-1]=mfib(n-1);
+ if (F[n-2]==-1) // if place is not called then
+ F[n-2]=mfib(n-2); // call recursively
+ if (F[n-1]==-1); // if this is also not called then
+ F[n-1]=mfib(n-1);// call recursively
36
37
- return F[n-2]+F[n-1];
+ return F[n-2]+F[n-1]; // at last return the sum of the called terms
38
39
40
0 commit comments