# Data Structure Questions and Answers-Decimal to Binary Conversion using Recursion

## Click on any option to know the CORRECT ANSWERS

 Question 1
Which of the following is the binary representation of 100?
 A 1010010 B 1110000 C 1100100 D 1010101

Question 1 Explanation:
100 = 64 + 32 + 4 = 26 + 25 + 22 = 1100100.

 Question 2
Consider the following iterative code used to convert a decimal number to its equivalent binary:

#include<stdio.h> void dec....to....bin(int n) { int arr[31], len = 0, i; if(n == 0) { arr[0] = 0; len = 1; } while(n != 0) { arr[len++] = n % 2; .....; } for(i=len-1; i>=0; i--) printf("%d", arr[i]); } int main() { int n = 10; dec....to....bin(n); return 0; }

Which of the following lines should be inserted to complete the above code?

 A n- B n /= 2 C n /= 10 D n++

Question 2 Explanation:
The line "n /= 2" should be inserted to complete the above code.

 Question 3
What is the output of the following code?

#include<stdio.h> void dec....to....bin(int n) { int arr[31], len = 0, i; if(n == 0) { arr[0] = 0; len = 1; } while(n != 0) { arr[len++] = n % 2; n /= 2; } for(i=len-1; i>=0; i--) printf("%d", arr[i]); } int main() { int n = 63; dec....to....bin(n); return 0; }
 A 111111 B 111011 C 101101 D 101010

Question 3 Explanation:
The program prints the binary equivalent of 63, which is 111111.

 Question 4
What is the output of the following code?

#include<stdio.h> void dec....to....bin(int n) { int arr[31], len = 0, i; if(n == 0) { arr[0] = 0; len = 1; } while(n != 0) { arr[len++] = n % 2; n /= 2; } for(i=len-1; i>=0; i--) printf("%d", arr[i]); } int main() { int n = 0; dec....to....bin(n); return 0; }
 A 0 B 1 C Runtime error D Garbage value