WAP to Find the Minimum and Maximum Element of the Array in C

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.

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

Output

C Program for Minimum and Maximum

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

See Also

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

Leave a Comment