C Program to find Maximum and Minimum number from a list of numbers

/* MAX-MIN USING DIRECT APPROACH */

#include<stdio.h>
#include<conio.h>

void main()
{
 int n, arr[50], i;
 int max, min;
 clrscr();
 printf("\nEnter number of elements: ");
 scanf("%d", &n);
 printf("\nEnter the elements: ");
 for(i=0; i<n; i++)
  scanf("%d", &arr[i]);

 max=a[0];
 min=a[0];

 for(i=0; i<n; i++)
 {
  if(arr[i]>max)
   max=arr[i];
  if(arr[i]<min)
   min=arr[i];
 }

 printf("\nMaximum element=%d", max);
 printf("\nMinimum element=%d", min);

 getch();
}

/* OUTPUT


Enter number of elements: 5

Enter the elements: 6 -4 9 0 -2

Maximum element=9
Minimum element=-4
*/

Comments