C - A4P2 - Find minimum and maximum of an array




/* Write a program to find minimum and maximum value from an array */


#include<stdio.h>
#include<conio.h>
void main()
{
    int arr[5],a,max,min;
    clrscr();
    for(a=0;a<5;a++)
    {
        printf("Enter Element -> ");
        scanf("%d",&arr[a]);
    }
    max=min=arr[0];
    for(a=0;a<5;a++)
    {
        if(arr[a]>max)
        {
            max=arr[a];
        }
        if(arr[a]<min)
        {
            min=arr[a];
        }
    }
    printf("\n\nMaximum Element in array is -> %d",max);
    printf("\nMinimum Element in array is -> %d",min);
    getch();
}

Post a Comment