Maximum and minimun in an array

 

Maximum and minimun in an array


C Program
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int n,i,max,min;
    printf("Enter the size of the array:");
    scanf("%d",&n);
    int array[n];
    for(i=0;i<n;i++)
    {
        printf("Enter the elemnt %d ",(i+1));
        scanf("%d",&array[i]);
    }
    max=array[0];
    min=array[1];
    for(i=0;i<n;i++)
    {
        if(array[i]>max)
            max=array[i];
        if(array[i]<min)
            min=array[i];
    }
    printf("The max is %d\n",max);
    printf("The min is %d",min);

}

2 comments:

  1. Write the c program to solve/compute average of the numbers in array

    ReplyDelete
    Replies
    1. Find sum of numbers of the array and divide by the size of the array that's all

      Delete