How to find the minimum element in an array. Finding the minimum of an Array

Get the algorithm and the code in C language on how to find the minimum element in an array.

Finding the minimum of an array is the basis for more advanced sorting operations in DSA.

Algorithm

STEP 1: min=A[0]
STEP 2: FOR(I=1 TO N) DO
STEP 3: IF(min>A[i])DO
STEP 4: min=A[I]
STEP 6: ENDIF
STEP 7: ENDFOR
STEP 8: STOP

Code

#include <stdio.h>
int main()
{
int n;
printf("enter the limit ");
scanf("%d",&n);
int a[n];
printf("enter the elements ");
for(int i=0;i<n;i++) 
{
printf("a[%d]",i);
scanf("%d",&a[i]);
}int min=a[0];
for(int i=0;i<n;i++)
{
if(min>a[i])
min=a[i];
}
printf("THE SMALLEST ELEMENT IS %d",min);
return 0;
}

Output

user@computer$ : enter the limit 5
enter the elements a[0]2
a[1]3
a[2]1
a[3]3
a[4]5
THE SMALLEST ELEMENT IS 1

Click here to get the algorithm and the code in C for merging two arrays.

Click here to get the algorithm and the code in C for reversing all the elements of an array ( array reversal)

Leave a Comment

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