Want to convert decimal number to binary number using recursion in R programming language. Use the below R program and execute it to convert decimal into binary using recursion in R with the output.
1 2 3 4 5 6 7 8 9 10 | # R program to convert decimal number into # binary number using recursive function convert_to_binary <- function(n) { if(n > 1) { convert_to_binary(as.integer(n/2)) } cat(n %% 2) } |
Program Output
1 2 | > convert_to_binary(52) 110100 |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.