DOWNLOAD FREE PDF <<CLICK HERE>>
Data Structure Questions and Answers-Largest and Smallest Number in an Array using Recursion
Congratulations - you have completed Data Structure Questions and Answers-Largest and Smallest Number in an Array using Recursion.
You scored %%SCORE%% out of %%TOTAL%%.
Your performance has been rated as %%RATING%%
Your answers are highlighted below.
Question 1 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER] |
Which of the following methods can be used to find the largest and smallest element in an array?
Recursion | |
Iteration | |
Both recursion and iteration | |
None of the mentioned |
Question 1 Explanation:
Both recursion and iteration can be used to find the largest and smallest element in an array.
Question 2 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER] |
Consider the following iterative code snippet to find the largest element:
int get....max....element(int *arr, int n) { int i, max....element = arr[0]; for(i = 1; i < n; i++) if(.....) max....element = arr[i]; return max....element; }
Which of the following lines should be inserted to complete the above code?
arr[i] > max....element | |
arr[i] < max....element | |
arr[i] == max....element | |
none of the mentioned |
Question 2 Explanation:
The line "arr[i] > max....element" should be inserted to complete the above code snippet.
Question 3 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER] |
Consider the following code snippet to find the smallest element in an array:
int get....min....element(int *arr, int n) { int i, min....element = arr[0]; for(i = 1; i < n; i++) if(.....) min....element = arr[i]; return min....element; }
Which of the following lines should be inserted to complete the above code?
arr[i] > min....element | |
arr[i] < min....element | |
arr[i] == min....element | |
none of the mentioned |
Question 3 Explanation:
The line "arr[i] < min....element" should be inserted to complete the above code.
Question 4 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER] |
What is the output of the following code?
#include<stdio.h> int get....max....element(int *arr, int n) { int i, max....element = arr[0]; for(i = 1; i < n; i++) if(arr[i] > max....element) max....element = arr[i]; return max....element; } int get....min....element(int *arr, int n) { int i, min....element = arr[0]; for(i = 1; i < n; i++) if(arr[i] < min....element) min....element = arr[i]; return min....element; } int main() { int n = 7, arr[7] = {5, 2, 4, 7, 8, 1, 3}; int max....element = get....max....element(arr, n); int min....element = get....min....element(arr, n); printf("%d %d", max....element, min....element); return 0; }
5 3 | |
3 5 | |
8 1 | |
1 8 |
Question 4 Explanation:
The program prints the values of the largest and the smallest elements in the array, which are 8 and 1 respectively.
Question 5 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER] |
What is the output of the following code?
#include<stdio.h> int get....max....element(int *arr, int n) { int i, max....element = arr[0]; for(i = 1; i < n; i++) if(arr[i] > max....element) max....element = arr[i]; return max....element; } int get....min....element(int *arr, int n) { int i, min....element; for(i = 1; i < n; i++) if(arr[i] < min....element) min....element = arr[i]; return min....element; } int main() { int n = 7, arr[7] = {1, 1, 1, 0, -1, -1, -1}; int max....element = get....max....element(arr, n); int min....element = get....min....element(arr, n); printf("%d %d", max....element, min....element); return 0; }
1 -1 | |
-1 1 | |
1 Garbage value | |
Garbage value -1 |
Question 5 Explanation:
Since the min....element variable is not initialised, the get....min....element() function will return a garbage value.
Once you are finished, click the button below. Any items you have not completed will be marked incorrect.
There are 5 questions to complete.