asked 16.3k views
0 votes
Write a function that returns a pointer to the maximum value of an array of float ingpoint data: double* maximum(double* a, int size) If size is 0, return NULL.

asked
User S M
by
7.8k points

1 Answer

7 votes

Answer:

double * maximum( double arr[], int size){

int max = 0;

if ( size == 0){

return 0;

} else {

for (int i = 1; i < size; i++){

if (arr[i] > arr[0]){

max = arr[i];

} else {

max = arr[0];

}

}

return max;

}

}

Step-by-step explanation:

The C++ source code above returns the maximum value of an array as a pointer. The function accepts two parameters, the array in question and the size of the array. The for loop iterates over the items in the array and checks for the largest, which is returned as a pointer since the function "maximum" is defined as a pointer to the floating-point number memory location.

answered
User Phylogenesis
by
8.5k points