Consider the following snippet of a C program. Assume that swap (&x, &y) exchanges the contents of x and y.
The output of the program is ________.
c
Programming in CFunctions, Parameter Passing, Scope Rules, RecursionNAT2 marksMedium
1int main() {
2 int array[] = {3, 5, 1, 4, 6, 2};
3 int done = 0;
4 int i;
5 while (done == 0) {
6 done = 1;
7 for (i = 0; i <= 4; i++) {
8 if (array[i] < array[i + 1]) {
9 swap(&array[i], &array[i + 1]);
10 done = 0;
11 }
12 }
13 for (i = 5; i >= 1; i--) {
14 if (array[i] > array[i - 1]) {
15 swap(&array[i], &array[i - 1]);
16 done = 0;
17 }
18 }
19 }
20 printf("%d", array[3]);
21}
22A GATE question every morning
One real past-paper question every morning for your branch, answer hidden until you tap. Free on Telegram.