BEGIN PROGRAM mystery(int a, int b)
IF (b == 1)
RETURN a
END IF
ELSE
RETURN a + mystery(a, b-1)
END ELSE
END PROGRAM mystery
mystery(2, 3) //a = 2, b = 3.
b is not 1, so should return 2 + mystery(2, 2).
a = 2, b = 2.
b is not 1, so should return 2 + mystery(2, 1).
a = 2, b = 1.
b is 1, so should return 2.
So, going back mystery(2, 1) is replaced with 2, so, should
return 2 + 2 = 4.
going back mystery(2, 2) is replaced with 4, so, should return 2 +
4 = 6.
Therefore, the answer is: 6.
Consider the following pseudo-code fragment. What is the value of mystery(2, 3)? BEGIN PROGRAM mystery(int a,...
5.43 (10 pts) What does the following program do? #include <stdio.h> 3 unsigned int mystery Cuns igned int a, unsigned int b): // function prototype 5 int main(void) printf("%s". "Enter two positive integers: unsigned int x: I/ first integer unsigned int y: // second integer scanf("Su%u". &x, &y); "); 12 13 14 15 II Parameter b must be a positive integer 16 to prevent infinite recursion 7 unsigned int mystery Cuns igned int a, unsigned int b) 18 printf("The result...
Consider the following code segment: int[][] mystery = new int[3][3]; int counter = 0; while(counter < mystery.length) { for(int col = 0; col < mystery[counter].length; col++) { if(counter == 0) { mystery[col][counter] = 1; } else if(counter == 1) { mystery[counter][col] = 2; } else { mystery[counter][counter] = 3; } } counter++; } What will the value of each element in mystery be after the execution of the code segment? a) {{1, 0, 0} {2, 2, 2} {1, 0, 3}}...
3. Consider the mystery method given. public static int mystery ( int n) [ if (n == 0 ) { return 1; How do we get the values for recurse? else if (n%2 == 0 ) { int recurse = mystery ( n - 1); int result = recurse + n; return result; since n =5, we go to the else statement and do int recurse = mystery(5-1) which equals 4? why is 3 written? else { int recurse =...
Consider the following method: Linel: public static int mystery(int n) { Line2: if (n < 10) { ine3: return n; Line4: } else { Line5: int a = n/10; Line 6: int b = n % 10; Line 7: return mystery(a + b); Line 8: } Line 9: } What is the result of the following call? System.out.println(mystery(648)); 18 8 12
Consider the following pseudo code. What are the possible outputs (.e., the complete output from each execution run of this program)? Explain in less than 50 words. Note: keep in mind that fork) may fail in that case no child process is created int main(int arge, char argvt int X- int CwO; re - fork(); 15 tre > 0) X=S; else x-rc +2: printf(" \n", x); return 0;
Consider the following method: public static int mystery (int x, double y, char ch) { int u; if ('A' <= ch && ch <= 'R') return (2 * x + (int)(y)); else return((int)(2 * y) - x); } What is the output of the following Java statements? a. System.out.println (mystery(5, 4.3, 'B')); b. System.out.println (mystery(4, 9.7, 'v')); c. System.out.println (2 * mystery(6, 3.9, 'D'));
Consider the following method. public static ArrayList<Integer mystery(int n) ArrayList<Integer seg - new ArrayList<IntegerO; for (int k = n; k > 0; k--) seq.add(new Integer(k+3)); return seq What is the final output of the following Java statement? System.out.println(mystery(3)); a. [1,2,4,5) b. [2,3,4,5) c. [6,5,4,3] d. [7, 7, 8, 8] e. [7,8,9, 8) O Consider the following method: public static int mystery(int[] arr, int k) ifk-0) return 0; }else{ return arr[k - 1] + mystery(arr, k-1):) The code segment below is...
3) What are the final values of a, b, c in the following code fragment (1.5 point): int a = 6 , b = 127 , c; c = ( ++a ) + ( b -- ); Answer: 4) What are the final values of a, b, c in the following code fragment (1.5 point): int a = 6 , b = 127 , c; c = (a++) + ( -- b); Answer: 5) What is displayed by this poorly...
What is the value of x[2] after execution of this code fragment? int x[4] = {3, 6, 9, 5}; x[2] -= x[1] % x[3]; 1 2 3 8
Consider carefully the program fragment below: int items = 5; ... if (items/2 == 2.5) cout << "items = 5\n"; else cout << "items != 5\n"; What is its output? Depends on the value of a at the time of execution of the if clause item=5 item != 5 None of the Above