in Programming in C
369 views
0 votes
0 votes

 

What does fun2() do in general?

int fun(int x, int y)

{

    if (y == 0)   return 0;

    return (x + fun(x, y-1));

}

 

int fun2(int a, int b)

{

    if (b == 0) return 1;

    return fun(a, fun2(a, b-1));

}

in Programming in C
by
369 views

3 Comments

power function i.e ab.

0
0
How?!
0
0

Note that, fun(a,b) returns a*b as output

fun2(a,b) = fun (a,fun2(a,b-1)) = a * fun2(a,b-1) --------------> (1)

                                           = a* fun(a,fun2(a,b-2))

                                           = a * a * fun2(a,b-2) --------------> (2)

from 1 and 2, you can generalize, it as ab.

0
0

Please log in or register to answer this question.

Related questions