Consider the following recursive function fun (s , y). what is the value of fun ( 4, 3) int fun ( int x , int y) if ( x =0) return y; return fun ( x,1, x+y); |
Consider the following recursive function fun (s , y). what is the value of fun ( 4, 3) int fun ( int x , int y) if ( x =0) return y; return fun ( x,1, x+y); | Correct Answer 13
The function fun() calculates and returns ((1 + 2 … + x - 1 + x) + y) which is x(x + 1)/2 + y. After Completing X = 4 y = 3 Output 1st Pass 3 7 No 2nd Pass 2 10 No 3rd Pass 1 12 No 4th Pass 0 13 No 5th pass The (x = = 0) evaluates and gives output y = 13 13
মোঃ আরিফুল ইসলাম
Feb 20, 2025