Arrays are the fundamental data structure in C programming, often used to store the collection of data of the same data type. A common challenge while working with arrays is determining the smallest(minimum) and the largest(maximum) elements. In this article, we will write a C program to efficiently find the minimum and maximum elements of the array.

## Table of Contents

## Algorithm for Minimum and Maximum

The algorithm for finding the minimum and maximum elements in an array is straight forward-

- Strat with assuming that the first element of the array is both the minimum and maximum.
- Iterate through the array starting from the second element.
- Compare each element and if the current element is less than the minimum, update the minimum, or if it is greater than the maximum update the maximum.
- After traversing the entire array the minimum and the maximum variables hold the desired values.

## C Program for Minimum and Maximum

```
#include <stdio.h>
void main()
{
int array[] = {6, 7, 8, 4, 2, 67, 23, 56};
int n = sizeof(array) / sizeof(array[0]);
int min = array[0];
int max = array[0];
for (int i = 1; i < n; i++)
{
if (array[i] > max)
{
max = array[i];
}
if (array[i] < min)
{
min = array[i];
}
}
printf("Minimum element of array = %d\n", min);
printf("Maximum element of array = %d\n", max);
}
```

### Output

Writing a program to find minimum and maximum elements in an array is an excellent exercise for understanding the array manipulation iteration in C.

*Happy Coding*

## 3 thoughts on “WAP to Find the Minimum and Maximum Element of the Array in C”