Question: 2.1) The program in Figure 1 performs certain task. Compile the program and answer the following questions: a) What is the value of d ?

2.1) The program in Figure 1 performs certain task. Compile the program and answer the following questions: a) What is the value of d ? (2 marks) b) What is the value of d if num[] is stored with {33,44,55,77,66,55,44,99,22,11} ? (2 marks) c) What is the value of d if num[] is stored with the numeral digits of your student number? (for example BK20123456, will be stored as 2,0,1,2,3,4,5,6 ) (2 marks) d) Based on the values of d, what does the Mystery function do? (2 marks) 2.2) Write another program that can perform the same task. The program should be different from the one given in Figure 2. *Copy and paste your program AND output. (6 marks) \#include using namespace std; int Mystery(int array[], int a, int b); int main() \{ int a1,a2,d; int num[] ={17,0,61,12,200,10,69,55,77,123,29}; a1 = 0; a2 = sizeof(num) / sizeof(num[0])-1; d= Mystery(num, a1, a2); cout "The value of d is " d; return 0 ; \} int Mystery(int array[], int a, int b) \{ int c; if (a==b) return array[a]; else \{ c= Mystery ( array ,a+1,b) if(array[a] >= c) return array[a]; else return c; \} \}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
