write and test a function that returns the difference between the largest and the smallest elements of an array-of- double . be sure to test (and include) all the edge cases you can think of to ensure your function works for all double variables.
1
Expert's answer
2021-10-13T10:43:41-0400
double diff(double *arr) {
int n = sizeof(arr) / sizeof(arr[0]);
double min = DBL_MAX;
double max = DBL_MIN;
for (int i = 0; i < n; i++) {
if (min > arr[i]) { min = arr[i]; }
if (max < arr[i]) { max = arr[i]; }
}
return max - min;
}
Comments
Leave a comment