Computer Science
Write a program to display first four multiples of a number using recursion.
Python
Python Functions
1 Like
Answer
def display_multiples(n, count = 1):
if count > 4:
return
print(n * count)
display_multiples(n, count + 1)
n = int(input("Enter the number: "))
display_multiples(n)
Output
Enter the number: 11
11
22
33
44
Answered By
2 Likes
Related Questions
Write a function that takes amount-in-dollars and dollar-to-rupee conversion price; it then returns the amount converted to rupees. Create the function in both void and non-void forms.
Write a function to calculate volume of a box with appropriate default values for its parameters. Your function should have the following input parameters :
(a) length of box ;
(b) width of box ;
(c) height of box.
Test it by writing complete program to invoke it.
What do you understand by recursion ? State the advantages and disadvantages of using recursion.
Write a recursive function to add the first 'n' terms of the series:
1 + 1/2 - 1/3 + 1/4 - 1/5……………