Skip to content

Commit 8808751

Browse files
authored
Create Decimal value to Binary value
1 parent 52d62ac commit 8808751

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Decimal value to Binary value

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def decimal_to_binary(n):
2+
if n > 1:
3+
decimal_to_binary(n // 2) # Recursive call
4+
print(n % 2, end="")
5+
6+
# Example usage:
7+
decimal_number = 10 # Replace with the decimal number you want to convert
8+
print(f"The binary equivalent of {decimal_number} is: ", end="")
9+
decimal_to_binary(decimal_number)

0 commit comments

Comments
 (0)