Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Which of the following functions returns the largest value in the array X? int b

ID: 3918949 • Letter: W

Question

Which of the following functions returns the largest value in the array X?

int big(int X[ ], int arraySize) {

int large = X[arraySize];

for ( int i = 0; i< arraySize; i++)

if (X[i] > large)

large = X[i];

return large;

}

int big(int X[ ], int arraySize) {

int large = X[0];

for ( int i = 0; i< arraySize; i++)

if (X[i] > large)

large = X[i];

return large;

}

int big(int X[ ], int arraySize) {

int large = X[0];

for ( int i = 0; i< arraySize; i++)

if (X[i] < large)

large = X[i];

return large;

}

int big(int X[ ], int arraySize) {

int large = X[0];

for ( int i = 0; i<= arraySize; i++)

if (X[i] > large)

large = X[i];

return large;

}

int big(int X[ ], int arraySize) {

int large = X[arraySize];

for ( int i = 0; i< arraySize; i++)

if (X[i] > large)

large = X[i];

return large;

}

Explanation / Answer

Answer : (B) ( Considering A ,B,C,D from top to bottom. )

The function A contains int large = X[arraySize]; , which is wrong as array indies lies between 0 to (arraySize -1 )

The Function C contains wrong logic

if (X[i] < large)

large = X[i];

If X[i] < large than large cannot be equal to X[i]

The function D contains array out of bound error as the loop runs until I = arraySize instead of arraySize-1

Please Up vote.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote