GATE Exam  >  GATE Questions  >  Consider the following C function in which si... Start Learning for Free
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
  • a)
    maximum possible sum of elements in any sub-array of array E.
  • b)
    maximum element in any sub-array of array E.
  • c)
    sum of the maximum elements in all possible sub-arrays of array E.
  • d)
    the sum of all the elements in the array E
Correct answer is option 'A'. Can you explain this answer?
Most Upvoted Answer
Consider the following C function in which size is the number of eleme...
The given C function `MyX` takes an array `E` and the number of elements in the array `size` as input. It initializes three variables `Y`, `Z`, and `i` to 0, and two more variables `j` and `k` without any initial value.

The function then enters a for loop that iterates from 0 to `size-1` (inclusive) with the variable `i`. Inside the for loop, the function multiplies the value of `Y` by 2 and assigns the result back to `Y`. It then adds the value of `E[i]` to `Y` and assigns the result back to `Y`.

After the for loop ends, the function declares a new variable `X` without any initial value and assigns the value of `Y` to `X`. It then enters another for loop that iterates from 0 to `size-1` (inclusive) with the variable `j`. Inside this for loop, the function updates the value of `X` by adding `E[j]` to it.

The function then enters a nested for loop with variables `j` and `k`. The outer for loop iterates from 0 to `size-1` (inclusive) with the variable `j`, and the inner for loop iterates from `j+1` to `size-1` (inclusive) with the variable `k`. Inside this nested for loop, the function checks if `E[k]` is greater than `E[j]`. If it is, the function swaps the values of `E[k]` and `E[j]`.

Finally, the function returns the value of `X`.

Overall, the function calculates the sum of the elements in the array `E`, doubles it, and then adds the sum again. It also sorts the array `E` in ascending order before returning the sum.
Explore Courses for GATE exam
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 thea)maximum possible sum of elements in any sub-array of array E.b)maximum element in any sub-array of array E.c)sum of the maximum elements in all possible sub-arrays of array E.d)the sum of all the elements in the array ECorrect answer is option 'A'. Can you explain this answer?
Question Description
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 thea)maximum possible sum of elements in any sub-array of array E.b)maximum element in any sub-array of array E.c)sum of the maximum elements in all possible sub-arrays of array E.d)the sum of all the elements in the array ECorrect answer is option 'A'. Can you explain this answer? for GATE 2024 is part of GATE preparation. The Question and answers have been prepared according to the GATE exam syllabus. Information about 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 thea)maximum possible sum of elements in any sub-array of array E.b)maximum element in any sub-array of array E.c)sum of the maximum elements in all possible sub-arrays of array E.d)the sum of all the elements in the array ECorrect answer is option 'A'. Can you explain this answer? covers all topics & solutions for GATE 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for 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 thea)maximum possible sum of elements in any sub-array of array E.b)maximum element in any sub-array of array E.c)sum of the maximum elements in all possible sub-arrays of array E.d)the sum of all the elements in the array ECorrect answer is option 'A'. Can you explain this answer?.
Solutions for 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 thea)maximum possible sum of elements in any sub-array of array E.b)maximum element in any sub-array of array E.c)sum of the maximum elements in all possible sub-arrays of array E.d)the sum of all the elements in the array ECorrect answer is option 'A'. Can you explain this answer? in English & in Hindi are available as part of our courses for GATE. Download more important topics, notes, lectures and mock test series for GATE Exam by signing up for free.
Here you can find the meaning of 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 thea)maximum possible sum of elements in any sub-array of array E.b)maximum element in any sub-array of array E.c)sum of the maximum elements in all possible sub-arrays of array E.d)the sum of all the elements in the array ECorrect answer is option 'A'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of 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 thea)maximum possible sum of elements in any sub-array of array E.b)maximum element in any sub-array of array E.c)sum of the maximum elements in all possible sub-arrays of array E.d)the sum of all the elements in the array ECorrect answer is option 'A'. Can you explain this answer?, a detailed solution for 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 thea)maximum possible sum of elements in any sub-array of array E.b)maximum element in any sub-array of array E.c)sum of the maximum elements in all possible sub-arrays of array E.d)the sum of all the elements in the array ECorrect answer is option 'A'. Can you explain this answer? has been provided alongside types of 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 thea)maximum possible sum of elements in any sub-array of array E.b)maximum element in any sub-array of array E.c)sum of the maximum elements in all possible sub-arrays of array E.d)the sum of all the elements in the array ECorrect answer is option 'A'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice 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 thea)maximum possible sum of elements in any sub-array of array E.b)maximum element in any sub-array of array E.c)sum of the maximum elements in all possible sub-arrays of array E.d)the sum of all the elements in the array ECorrect answer is option 'A'. Can you explain this answer? tests, examples and also practice GATE tests.
Explore Courses for GATE exam
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev