GATE CS 2017, set 2 · Question 43 · Programming and Data Structures · Numerical answer (NAT) · 2 marks · no negative marks

Consider the following snippet of a C program. Assume that swap(&x, &y) exchanges the contents of x and y.
int main() { int array[] = {3, 5, 1, 4, 6, 2}; int done = 0; int i; while (done == 0) { done = 1; for (i=0; i<=4; i++) { if (array[i] < array[i+1]) { swap(&array[i], &array[i+1]); done = 0; } } for (i=5; i>=1; i--) { if (array[i] > array[i-1]) { swap(&array[i], &array[i-1]); done = 0; } } } printf("%d",array[3]); }
The output of the program is ______.

Answer

Answer 3

Answer from the official GATE CS 2017 answer key.

The step-by-step solution, where available, is part of GATE CS Pro. See what Pro includes