Find max. and min. element in the integer array




#include<stdio.h>

#include <conio.h>

int main()

{

    int a[1000],i,n,min,max;

   

    printf("Enter size of the array : ");

    scanf("%d",&n);

 

    printf("Enter elements in array : ");

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

    {

        scanf("%d",&a[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);

 

 

    return 0;

}


Output:-

Enter size of the array: 5 Enter elements in array: 1 2 3 4 5 minimum of an array is: 1 maximum of an array is: 5

Comments

Popular posts from this blog

Check whether the no entered is Palindrome or not

Calculate Factorial of a given no with help of Recursion