Minimum and maximum number from an array - C - A5P7



/* write a program to find the minimum and maximum number from an array */

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

Post a Comment