ProgrammingEasyAccenture · Cognizant pattern
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer a = 6, b = 4 a = a + b b = a - b a = a - b Print a, b
- A. 4 10
- B. 10 6
- C. 4 6
- D. 6 4
Correct answer: C. 4 6
a = 10, then b = 10 - 4 = 6, then a = 10 - 6 = 4. This is the classic swap without a third variable.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode? Integer n = 5, f = 1 while (n > 1) f = f n n = n - 1 end while Print f
- What will be the output of the following pseudocode? (Arrays are indexed from 0.) Integer arr[4] = {4, 9, 2, 7} Integer m = arr[0] for…
- What will be the output of the following pseudocode? Integer x = 10 if (x > 5) x = x 2 else x = x + 2 end if if (x > 15) x = x - 3 end if…
- What will be the output of the following pseudocode? Integer c = 0 for (each i from 1 to 20) if (i mod 3 == 0 or i mod 5 == 0) c = c + 1…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division.) Integer n = 4521, r = 0 while…
- What will be the output of the following pseudocode? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right…