The program defines a recursive function multiple that takes two integers a and b as arguments and returns their product. The function works by repeatedly adding a to itself b times using recursion, until the value of b becomes 1, at which point the function simply returns a. If the value of b is negative, the function calls itself with b replaced by its absolute value and the sign of the result is negated. If b is 0, the function simply returns 0.
In the main program, the user is prompted to enter two integers a and b, which are then passed as arguments to the multiple function. The result of the multiplication is then printed to the console.
def multiple(a,b): if b < 0: return -multiple(a, -b) elif b == 0: return 0 elif b == 1: return a else: return a + multiple(a, b - 1) a = int(input("Enter the Number :")) b = int(input("Enter the Number :")) print(multiple(a,b))
Enter the Number :12 Enter the Number :34 408
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions