Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
29
Task/Anonymous-recursion/C/anonymous-recursion-1.c
Normal file
29
Task/Anonymous-recursion/C/anonymous-recursion-1.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#include <stdio.h>
|
||||
|
||||
long fib(long x)
|
||||
{
|
||||
long fib_i(long n) { return n < 2 ? n : fib_i(n - 2) + fib_i(n - 1); };
|
||||
if (x < 0) {
|
||||
printf("Bad argument: fib(%ld)\n", x);
|
||||
return -1;
|
||||
}
|
||||
return fib_i(x);
|
||||
}
|
||||
|
||||
long fib_i(long n) /* just to show the fib_i() inside fib() has no bearing outside it */
|
||||
{
|
||||
printf("This is not the fib you are looking for\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
long x;
|
||||
for (x = -1; x < 4; x ++)
|
||||
printf("fib %ld = %ld\n", x, fib(x));
|
||||
|
||||
printf("calling fib_i from outside fib:\n");
|
||||
fib_i(3);
|
||||
|
||||
return 0;
|
||||
}
|
||||
13
Task/Anonymous-recursion/C/anonymous-recursion-2.c
Normal file
13
Task/Anonymous-recursion/C/anonymous-recursion-2.c
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#include <stdio.h>
|
||||
int main(){
|
||||
int n = 3;
|
||||
printf("%d",({
|
||||
int fib(int n){
|
||||
if (n <= 1)
|
||||
return n;
|
||||
return fib(n-1) + fib(n-2);
|
||||
}
|
||||
fib(n);
|
||||
}));
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue