Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
30
Task/Mutual-recursion/C/mutual-recursion.c
Normal file
30
Task/Mutual-recursion/C/mutual-recursion.c
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* let us declare our functions; indeed here we need
|
||||
really only M declaration, so that F can "see" it
|
||||
and the compiler won't complain with a warning */
|
||||
int F(const int n);
|
||||
int M(const int n);
|
||||
|
||||
int F(const int n)
|
||||
{
|
||||
return (n == 0) ? 1 : n - M(F(n - 1));
|
||||
}
|
||||
|
||||
int M(const int n)
|
||||
{
|
||||
return (n == 0) ? 0 : n - F(M(n - 1));
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 20; i++)
|
||||
printf("%2d ", F(i));
|
||||
printf("\n");
|
||||
for (i = 0; i < 20; i++)
|
||||
printf("%2d ", M(i));
|
||||
printf("\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue