225. Decimal to Binary
Foundation1000 ms256 MBSolved by 0%
Print the binary representation of n, with no leading zeros.
Dividing by 2 gives you the digits, and n % 2 gives you each one, but they
come out backwards: the first remainder you get is the LAST binary digit.
Recursion handles that neatly. Print the result for n / 2 first, then print
the current remainder. The reversal happens for free because the deeper calls
finish first.
Constraints - `0 ≤ n ≤ 1000000000`
Input
A single line containing one integer n.
Output
Print the binary form of n on one line, with no leading zeros.
Input5
Output101
Noteis a small value with a mixed pattern
Input0
Output0
Notemust print a single 0, not an empty line
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.