Program to find min and max of elements in array

 #include<stdio.h>


void main()

{

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


    do

    {

        printf("\nEnter no. of elements in between 1 and 50: ");

        scanf("%d",&n);

    }while(n<1 || n>50);


    printf("\nEnter the elements: ");

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

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


    max=a[0];

    min=a[0];


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

    {

        if(a[i]>max)

            max=a[i];


        if(a[i]<min)

            min=a[i];

    }


    printf("\nMax = %d and Min = %d",max,min);

}

Comments

Popular posts from this blog

Single Program Using All Automatic String Functions

C program for subtraction of two matrices (2D Arrays)

C program for Multiplication of Two matrices