Answer:
In Python:
def decimalToBinary(num):
if num == 0:
return 0
else:
return(num%2 + 10*decimalToBinary(int(num//2)))
decimal_number = int(input("Decimal Number: "))
print("Decimal: "+str(decimalToBinary(decimal_number)))
Explanation:
This defines the function
def decimalToBinary(num):
If num is 0, this returns 0
<em> if num == 0:
</em>
<em> return 0
</em>
If otherwise
else:
num is divided by 2, the remainder is saved and the result is recursively passed to the function; this is done until the binary representation is gotten
return(num%2 + 10*decimalToBinary(int(num//2)))
The main begins here.
This prompts the user for decimal number
decimal_number = int(input("Decimal Number: "))
This calls the function and prints the binary representation
print("Decimal: "+str(decimalToBinary(decimal_number)))