Skip to content

Beta · Data may be lost.Your data may be reset or lost.

GateBrew
← GATE CSE 2017 Set 2
Questions

Q43

NAT2 marksProgrammingAlgorithms

Consider the following snippet of a C program. Assume that swap (&x,&y)(\&x, \&y) exchanges the content of xx and yy:

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 _______

Sign in to save attempts.

Solutions and discussion are hidden while you attempt this question. They open once you check or show the answer.