Largest and Smallest Element of an Array in C

Calculating largest and smallest element in C is straightforward. All you have to do is scan through the array one element at a time and compare it with current largest or smallest value. Since you scan every element of array, there will be n (number of elements in the array) comparisons. Therefore the running time of this algorithm is $\Theta(n)$.

Calculation of Largest Element

Calculation of Smallest Element

This code is also available in GitHub.

SHARE Largest and Smallest Element of an Array in C

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Share