C Example | Find Maximum and Minimum Number in an Array

This c programming example code will show us how to find maximum and minimum number in an array.

#include <stdio.h>
#include <conio.h>
 
int sumofarray(int a[],int n)
{
 	int min,max,i;
 	min=max=a[0];
    for(i=1; i<n; i++)
    {
         if(min>a[i])
          min=a[i];   
           if(max<a[i])
            max=a[i];       
    }
    
    printf("minimum of array is : %d",min);
    printf("\nmaximum of array is : %d",max);
 }
int main()
{
    int a[1000],i,n,sum;
   
    printf("Enter size of the array : ");
    scanf("%d", &n);
 
    printf("Enter elements in array : ");
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    sumofarray(a,n);
}

Run this code, we will get:

Enter size of the array: 5
Enter elements in array: 1
2
35
0
-1
minimum of an array is: -1
maximum of an array is: 35