find the sum of largest and smallest number in an array in c program

find the sum of largest and smallest number in an array in c program

About the author
Margaret

1 thought on “find the sum of largest and smallest number in an array in c program”

  1. Answer:

    #include<stdio.h>

    int main()

    {

    int a[10],I,n,large,small;

    print(“\n Enter the number of elements : “);

    scanf(“%d”,&n);

    print(“\n Input the array elements : “);

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

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

    large=small=a[0];

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

    {

    if (a[i]>large)

    large=a[i];

    if(a[i]<small)

    small=a[i];

    }

    printf (“\n the smallest element Is %d\n”,small);

    printf(“\n The largest element is %d\n”,large);

    return 0;

    }

    OUTPUT :

    Enter the number of elements : 3

    Input the array elements : 2 4 6

    The smallest element is : 2

    The largest element is : 6

    Reply

Leave a Comment