Answer to Question #250837 in C for Samzzy

Question #250837
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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS