Consider the following pseudocode.
The value of sum output by a program executing the above pseudocode is ____________ (Answer in integer)
code
Programming, Data Structures and Algorithmsbasic data structures: stacks, queues, linked lists, trees, hash tablesNAT2 marksMedium
1Create empty stack S
2Set x=0, flag=0, sum=0
3Push x onto S
4while (S is not empty){
5 if (flag equals 0){
6 Set x = x+1
7 Push x onto S}
8 if (x equals 8):
9 Set flag=1
10 if (flag equals 1){
11 x = Pop(S)
12 if (x is odd):
13 Pop(S)
14 Set sum = sum + x}
15}
16Output sum
17A GATE question every morning
One real past-paper question every morning for your branch, answer hidden until you tap. Free on Telegram.