C Program to find maximum and minimum of an Array

C Program to find maximum and minimum of an Array

What is an array?

C Program to find maximum and minimum of an Array

Array is a collection of similar data types stored at contiguous memory location. It is a linear data structure. Data stored in array at a position is called index of the element. Index helps to identify the location of the element.


Code

#include<stdio.h>

int main()

{

    int i,a[5];

    for(i=0;i<5;i++)

    {

       scanf("%d",&a[i]);

   }

    int max=a[0],min=a[0],n=3; 

    for(i=0;i<n;i++) 

    {

        if(a[i]>max) 

        {

            max=a[i];

        }

        if(a[i]<min)

        {

            min=a[i];        

        }

    }

    printf("%d\n%d",max,min);

    return 0;

    }



Output

1
2
3
4
5
max=5 min=1
Load comments