Python Program to Convert Decimal to Binary Using Recursion

Levels of difficulty: , / perform operation:

Source Code:

# Python program to convert decimal number into binary number using recursive function

def binary(n):
   """Function to print binary number
   for the input decimal using recursion"""
   if n > 1:
   print(n % 2,end = '')

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


Enter an integer: 52

In this program, we convert decimal number entered by the user into binary using a recursive function. Decimal number is converted into binary by dividing the number successively by 2 and printing the remainder in reverse order.