# Data Structure Questions and Answers-Recursion

## Data Structure Questions and Answers-Recursion

 Question 11 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What will be the output of the following code?

`int cnt=0; void my....recursive....function(int n) { if(n == 0) return; cnt++; my....recursive....function(n/10); } int main() { my....recursive....function(123456789); printf("%d", cnt); return 0; }`
 A 123456789 B 10 C 0 D 9
Question 11 Explanation:
The program prints the number of digits in the number 123456789, which is 9.

 Question 12 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What will be the output of the following code?

`void my....recursive....function(int n) { if(n == 0) { printf("False"); 	 return; } if(n == 1) { printf("True"); return; } if(n%2==0) my....recursive....function(n/2); else { printf("False"); return; } } int main() { my....recursive....function(100); return 0; }`
 A True B False
Question 12 Explanation:
The function checks if a number is a power of 2. Since 100 is not a power of 2, it prints false.

 Question 13 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What is the output of the following code?

`int cnt = 0; void my....recursive....function(char *s,  int i) { if(s[i] == '\0') return; if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u') cnt++; my....recursive....function(s, i+1); } int main() { my....recursive....function("thisisrecursion", 0); printf("%d", cnt); return 0; }`
 A 6 B 9 C 5 D 10
Question 13 Explanation:
The function counts the number of vowels in a string. In this case the number is vowels is 6.

 Question 14 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What is the output of the following code?

`void my....recursive....function(int *arr,  int val,  int idx,  int len) { if(idx == len) { printf("-1"); return ; } if(arr[idx] == val) { printf("%d", idx); return; } my....recursive....function(arr, val, idx+1, len); } int main() { int array[10] = {7,  6,  4,  3,  2,  1,  9,  5,  0,  8}; int value = 2; int len = 10; my....recursive....function(array,  value,  0,  len); return 0; }`
 A 3 B 4 C 5 D 6
Question 14 Explanation:
The program searches for a value in the given array and prints the index at which the value is found. In this case, the program searches for value = 2. Since, the index of 2 is 4(0 based indexing), the program prints 4.

There are 14 questions to complete.