Python Program to Convert Decimal to Binary Using Recursion

In this example, we will write a recursive function to convert decimal to binary. To better understand this example, make sure you have knowledge of the following tutorials:-

Loading...

Python Program to Shuffle Deck of Cards

def binary(n):
    if n > 1:
        binary(n // 2)
    print(n % 2, end = '')

# Take decimal number from user
dec = int(input("Enter an integer: "))
binary(dec)

The output of the above program is:-

Enter an integer: 20
10100

Loading...
SHARE Python Program to Convert Decimal to Binary Using Recursion

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Share