Write a program that converts decimal number N into binary number and outputs it. However, it must be output using a recursive function.
The first line is given a decimal number N (1<=N<=1,000).
11
Print the binary number on the first line.
1011
function solution(n) {
let answer = '';
function DFS(L) {
answer = (L % 2) + answer;
if (L / 2 < 1) return;
DFS(Math.floor(L / 2));
}
DFS(n);
return answer;
}
function solution(n) {
let answer = '';
function DFS(n) {
if (n === 0) return;
else {
DFS(parseInt(n / 2));
answer += n % 2;
}
}
DFS(n);
return answer;
}