Find maximum and minimum value in an array

for maximum:

#include<stdio.h>
int main()
{
    int ary[7]={-99,45,100,37,89,-327,245};
    int  i,max=0;
    for(i=0;i<7;i++)
    {
        if(ary[i]>max)
        {
            max=ary[i];
        }
    }
    printf("%d\n",max);

    return 0;
}

 

for minimum:

#include<stdio.h>
int main()
{
    int ary[7]={-99,45,100,37,89,-327,245};
    int  i,min=0;
    for(i=0;i<7;i++)
    {
        if(ary[i]<min)
        {
            min=ary[i];
        }
    }
    printf("%d\n",min);

    return 0;
}

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published.