Algorithms | Recursion | Question 5

Last Updated :
Discuss
Comments

What does fun2() do in general? 

C++
#include <iostream>  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)); } 
C
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)); } 
Java
public class Main {     public static int fun(int x, int y) {         if (y == 0) return 0;         return (x + fun(x, y - 1));     }      public static int fun2(int a, int b) {         if (b == 0) return 1;         return fun(a, fun2(a, b - 1));     }      public static void main(String[] args) {         // Example usage     } } 
Python
def fun(x, y):     if y == 0:         return 0     return x + fun(x, y - 1)  def fun2(a, b):     if b == 0:         return 1     return fun(a, fun2(a, b - 1)) 
JavaScript
function fun(x, y) {     if (y === 0) return 0;     return x + fun(x, y - 1); }  function fun2(a, b) {     if (b === 0) return 1;     return fun(a, fun2(a, b - 1)); } 

x*y

x+x*y

xy

yx

Share your thoughts in the comments