284,983 views
17 votes
17 votes
(TCO 4) The following function returns the _____ of the array elements. int mystery(int a[], int n) { int x=a[0]; for (int i=1; i

User Agnsaft
by
2.5k points

1 Answer

16 votes
16 votes

Answer:

Answered below.

Step-by-step explanation:

The function returns the largest of n number of elements in the array.

It takes an int array parameter int[] a, and an integer parameter n. It then assigns the first element of the array to an integer variable X.

The for loop begins at the second element of the array and loops less than n number of times. In each iteration, it checks if the element is greater than X and swaps it with X.

The function finally returns X.

User Geoffrey Anderson
by
2.6k points