In this Python Program, we will learn how to convert decimal numbers to binary numbers using recursion. In this program, we will not use any built-in function for the conversion of decimal to binary conversion.
Here is the code of the program to convert decimal to binary.
# Python Program to Convert the Decimal to Binary Using Recursion
# Define a Recursive Function
def convertDecimalToBinary(n):
if n > 1:
convertDecimalToBinary(n//2)
print(n % 2,end = '')
# Take the Input from the User
decNum = int(input("Enter the Number: "))
print("Binary Number of {0} is: ".format(decNum))
# Calling the Function
convertDecimalToBinary(decNum)
Enter the Number: 55
Binary Number of 55 is:
110111
Comments