Consider the following C function in which size is the number of elements in…

GATE · 2014 · CS · Set 1 · Computer Science & IT

Consider the following C function in which size is the number of elements in the array E:

int MyX(int *E, unsigned int size)
{
    int Y = 0;
    int Z;
    int i, j, k;

    for(i = 0; i < size; i++)
        Y = Y + E[i];

    for(i = 0; i < size; i++)
        for(j = i; j < size; j++)
        {
            Z = 0;
            for(k = i; k <= j; k++)
                Z = Z + E[k];
            if (Z > Y)
                Y = Z;
        }
    return Y;
}

The value returned by the function MyX is the

  1. A.

    maximum possible sum of elements in any sub-array of array E.

  2. B.

    maximum element in any sub-array of array E.

  3. C.

    sum of the maximum elements in all possible sub-arrays of array E.

  4. D.

    the sum of all the elements in the array E.

Attempted by 165 students.

Sign up free to check your answer

Sign up free

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…