Question 1
EasyWhat will be the output of the following pseudocode?
Integer a = 7, b = 4
if (a > b)
Print a - b
else
Print b - a
end if
- A.
11
- B.
4
- C.
-3
- D.
3
Show answer and explanation
Answer: D
a > b is true, so a − b = 3 is printed.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Pseudocode and Output Prediction
What will be the output of the following pseudocode?
Integer a = 7, b = 4
if (a > b)
Print a - b
else
Print b - a
end if
11
4
-3
3
Answer: D
a > b is true, so a − b = 3 is printed.
What will be the output of the following pseudocode?
Integer n = 15
if (n mod 2 == 0)
Print "Even"
else
Print "Odd"
end if
Odd
Even
Nothing
15
Answer: A
15 mod 2 is 1, so the else branch prints 'Odd'.
What will be the output of the following pseudocode?
Integer marks = 72
if (marks >= 90)
Print "A"
else if (marks >= 75)
Print "B"
else if (marks >= 60)
Print "C"
else
Print "D"
end if
D
B
C
A
Answer: C
72 fails the first two tests and passes marks >= 60, so 'C'.
What will be the output of the following pseudocode?
Integer x = 5, y = 10
if (x > 3 AND y < 5)
Print 1
else
Print 0
end if
0
10
1
5
Answer: A
x > 3 is true but y < 5 is false, so the AND is false and 0 is printed.
What will be the output of the following pseudocode?
Integer x = 5, y = 10
if (x > 8 OR y > 8)
Print 1
else
Print 0
end if
1
10
0
5
Answer: A
y > 8 is true, so the OR is true and 1 is printed.
What will be the output of the following pseudocode?
Integer a = 4, b = 9, c = 6
Integer big = a
if (b > big)
big = b
end if
if (c > big)
big = c
end if
Print big
19
6
9
4
Answer: C
big starts at 4, becomes 9, and 6 isn't larger, so the maximum 9 is printed.
What will be the output of the following pseudocode?
Integer t = 0
if (t)
Print "True"
else
Print "False"
end if
Error
0
False
True
Answer: C
As in C, a condition of 0 counts as false.
What is the output of this pseudocode?
Integer a = 15
if (a mod 3 == 0 and a mod 5 == 0)
Print "FizzBuzz"
else if (a mod 3 == 0)
Print "Fizz"
else if (a mod 5 == 0)
Print "Buzz"
else
Print a
end if
FizzBuzz
Fizz
15
Buzz
Answer: A
15 is divisible by both 3 and 5, so the first branch runs.
What is the output of this pseudocode?
Integer marks = 72
if (marks >= 90)
Print "A"
else if (marks >= 75)
Print "B"
else if (marks >= 60)
Print "C"
else
Print "D"
end if
B
C
A
D
Answer: B
72 is below 75 but at least 60, so the third branch runs.
What is the output of this pseudocode?
Integer x = -4
if (x > 0)
Print "positive"
else if (x < 0)
Print "negative"
else
Print "zero"
end if
zero
positive
-4
negative
Answer: D
x is −4, which is less than 0, so the second branch prints "negative".