View the step-by-step solution to:

Question

I need help to create a C function that takes in an one-dimensional array of integers ar and size as parameters.

The function finds the minimum and maximum numbers of the array. The function returns the minimum and maximum numbers through the pointer parameters min and max via call by reference.

The function prototype is given as follows:

void findMinMax1D(int ar[], int size, int *min, int *max);


A sample program template is given below to test the function:


#include <stdio.h>

void findMinMax1D(int ar[], int size, int *min, int *max);

int main()

{

 int ar[40];

 int i, size;

 int min, max;

 printf("Enter array size: n");

 scanf("%d", &size);

 printf("Enter %d data: n", size);

 for (i=0; i<size; i++)

 scanf("%d", &ar[i]);

 findMinMax1D(ar, size, &min, &max);

 printf("min = %d; max = %dn", min, max);

 return 0;

}

void findMinMax1D(int ar[], int size, int *min, int *max)

{

 /* input code here */

}


Some sample input and output sessions are given below:

(1) Test Case 1:

Enter array size:

5

Enter 5 data:

1 2 3 5 6

min = 1; max = 6


(2) Test Case 2:

Enter array size:

6

Enter 6 data:

-4 0 -7 3 2 1

min = -7; max = 3


(3) Test Case 3:

Enter array size:

1

Enter 1 data:

1

min = 1; max = 1


Hi would you be able to explain the code too? Thanks

Top Answer

#include &lt;stdio.h&gt; #include&lt;limits.h&gt; void findMinMax1D ( int ar[], int size, int *min, int *max) ; int main () {... View the full answer

min_max.PNG

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question