How to write a C Program Recursive in C Programming Language ?
Solution For C Program :
/* recursive */int foo(int a, int b, int c, int d)
{
if (a > c || b > d)
return 0;
else if (a == c && b == d)
return 1;
else
return foo(a + 1, b, c, d) +
foo(a, b + 1, c, d);
}
/* iterative (magic) */
int bar (int a, int b, int c, int d)
{
int num = 1;
int den = 1;
c = c - a;
d = d - b;
for (int i = 0; i < c /* or d */; i++)
{
num *= c + d - i;
den *= i + 1;
}
return num / den;
}