Decimal to Binary
Level MEDIUM
Given a decimal number (integer N), convert it into binary and print.
The binary number should be in the form of an integer.
Note : The given input number could be large, so the corresponding binary number can exceed the integer range. So you may want to take the answer as long for CPP and Java.
Input format :
Output format :
Constraints :
Sample Input 1 :
Sample Output 1 :
Sample Input 2 :
Sample Output 2 :
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Alorithm way | |
""" | |
def decimalToBinary(num): | |
if num>1: | |
decimalToBinary(num//2) | |
print(num%2,end="") | |
pass | |
decimalToBinary(num=int(input())) | |
""" | |
In built way | |
""" | |
print(bin(12).replace("0b","")) | |
Comments
Post a Comment
Please give us your valuable feedback