Gate CS-2017-2 Question Paper With Solutions

Q. 47 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] = 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 _____.
Note: This question appeared as Numerical Answer Type.

(A) 1

(B) 2

(C) 3

(D) 4

Answer: (C)

Explanation:

Gate CS-2017-2 Question Paper With Solutions

Learn More:   Gate EC-2003 Question Paper With Solutions

LEAVE A REPLY

Please enter your comment!
Please enter your name here