Print maximum & minimum array element - C Program

Write a 'C' Program to accept 'n' numbers from user, store these numbers into an array. Find out Largest and Smallest number from an array.

Solution:

#include <stdio.h>
int main()
{
     int a[20],i,g,l,n;
     printf("/*How Many Numbers You Want\nTo Add in an Array*/\n\nEnter Limit= ");
     scanf("%d",&n);
     printf("\nEnter %d Numbers:\n",n);
     for(i=0;i<n;i++)
          scanf("%d",&a[i]);
     /*To print largest number in array*/
     g=a[0];
     for(i=0;i<n;i++)
          if(a[i]>g)
               g=a[i];
     printf("Largest Number = %d\n",g);
     /*To print  smallest number in array*/
     l=a[0];
     for(i=0;i<n;i++)
          if(a[i]<l)
               l=a[i];
     printf("Smallest Number = %d",l);
     return 0;
}


Output:

max min array element