GATE Assistant

Past questions › Data Science and Artificial Intelligence › GATE 2025

GATE 2025 · DA · NAT · 2 marks · Programming, Data Structures and Algorithms › Stacks, Queues & Linked Lists

GATE 2025 Data Science and Artificial Intelligence question: Consider the following pseudocode. code The value of sum output by a program executing…

Consider the following pseudocode.

Create empty stack S
Set x=0, flag=0, sum=0
Push x onto S
while (S is not empty){
    if (flag equals 0){
        Set x = x+1
        Push x onto S}
    if (x equals 8):
        Set flag=1
    if (flag equals 1){
        x = Pop(S)
        if (x is odd):
            Pop(S)
        Set sum = sum + x}
}
Output sum

The value of sum output by a program executing the above pseudocode is ____________
(Answer in integer)

Show answer

Official answer: 24

Practise this question with exam-style marking

Discussion

No discussion yet.

Join the discussion