Let S be an integer stack on which push and pop can be performed. What is the…

Let S be an integer stack on which push and pop can be performed. What is the value of n printed by the following program fragment?

int a[10] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19};

for (int i = 0; i < 10; i++)

s.push(a[i]);

int n = 25;

for (int i = 0; i < 4; i++) {

n += s.pop();

}

for (int i = 0; i < 2; i++) {

n -= s.pop();

}

printf("%d", n);

Attempted by 176 students.

Sign up free to check your answer

Sign up free

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…