## Find Maximum and Minimum Values in an Array.

Last Updated On Thursday 9th Sep 2021

## Find Min and Max in array

• We will make a function return two values, the maximum and minimum values, and store them in another array.
• Thereafter, the array containing the maximum and minimum values will be returned from the function

### Min Find Max Find

	#include<stdio.h>

#define max 100
int * maxmin(int ar[], int v);
void main() {
int arr[max];
int n, i, * p;
printf("How many values? ");
scanf("%d", & n);
printf("Enter %d values\n", n);
for (i = 0; i < n; i++)
scanf("%d", & arr[i]);
p = maxmin(arr, n);
printf("Minimum value is %d\n", * p++);
printf("Maximum value is %d\n", * p);
}
int * maxmin(int ar[], int v) {
int i;
static int mm;
mm = ar;
mm = ar;
for (i = 1; i < v; i++) {
if (mm > ar[i])
mm = ar[i];
if (mm < ar[i])
mm = ar[i];
}
return mm;
}


	How many values? 4
Enter 4 values
11 22 52 01
Minimum value is 1
Maximum value is 52


• We will use Two Arrays.
• The first array will contain the values from which the maximum and minimum values have to be found.
• The second array will be used to store the minimum and maximum values of the first array.