C Program to find minimum element in an array without sorting
Program
#include<stdio.h>
void main()
{
int a[10], size, i, min, location;
printf("Enter the size of the array\n");
scanf("%d", &size);
printf("Enter %d elements\n", size);
for(i = 0; i < size; i++)
scanf("%d", &a[i]);
min = a[0];
location = 1;
for(i = 1; i < size; i++)
{
if(a[i] < min)
{
min = a[i];
location = i;
}
}
printf("Minimum element in the array is: %d and is present in location %d\n", a[location], location + 1);
}
Output
Enter the size of the array
5
Enter 5 elements
32
11
789
56
2
Minimum element in the array is: 2 and is present in location 5