CBSE Class 12 Computer Science Question 24 of 56

Functions — Question 24

Back to all questions
24
Question

Question 20

Write a program to display first four multiples of a number using recursion.

Solution
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
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