In this article, we are going to write a C Program to find the smallest element in a given array.
Coming to mathematics i am giving you a list of elements as follows.
Among this, find the smallest element. How you can do this. Initially assume that the first element is the minimum element.
Then we go for the second element that is ’60’ here.
we compare this with first element. 100>60, so we assume that the minimum value is now ’60’
Then we go to the next element in the array i.e. 55.
60>55 now the minimum value is 55.
what we are doing here is we have taken the first value as minimum, and we are comparing this element with the other elements in the array and finding the minimum element.
The same thing we are doing in the following program.
Process exited after 0.1691 seconds with return value 0
Press any key to continue . . .
We have taken an array with name ‘arr’ and initialized with ’10’ elements. we assigned the min value with ‘arr’ i.e. the first element in the array. Now we are comparing each element in the array with this value; if the array element is less than the ‘min’ value,then ‘min’ is assigned with the array element.