Find the minimum and maximum elements from array

Consider an array , we are asked to find the minimum and maximum elements from an array.
The explanation is :
consider two variables min,max and initialize them with INT_MAX,INT_MIN values
while you traverse across the array , if min variable value is greater than array element then min variable is reassigned to element and in the same way if max variable value is less than array element then max variable is reassigned to element.
Code for this problem is
#include
#include
void main()
{
int a[10]={1,4,2,3,6,5,7,8,0,9};
int i,min=INT_MAX,max=INT_MIN;
for(i=0;i<10;i++)
{
if(min>a[i])
min=a[i];
if(max
max=a[i];
}
printf("%d is minimum value\n %d is maximum value");
getch();
}
OUTPUT :
The output for this program will be
0 is minimum value
9 is maximum value
Execution trace
INITIAL min= 2147483648
max= -2147483647
i
element
max
min
0
1
1
1
1
4
4
1
2
2
4
1
3
3
4
1
4
6
6
1
5
5
6
1
6
7
7
1
7
8
8
1
8
0
8
0
9
9
9
0
This computes maximum and minimum values from array in 'N' iterations