Write a c program to find the sum of max and next max in a given array. for example int arr[]={2,5,68,2,4,32} The largest element is 68 and after this 32 is next largest them sum these two largest which is 68 + 32 = 100.

#include<stdio.h>
#include<stdlib.h>

/*comparator for quick sort*/
int comp(const void* a,const void* b)
{
    const int *x = (const int*)a;
    const int *y = (const int*)b;
    return (*y - *x);
}
void    print(int arr[],int size);
int main()
{

    int arr[]={2,5,68,2,4,32};
        int size = sizeof(arr)/sizeof(arr[0]);
    /*quick sort arr*/
    qsort(arr,size,sizeof(int),comp);
    
       //print(arr,size);
        printf("The Sum is %d \n",arr[0] + arr[1]);
return 0;
}
void    print(int arr[],int size)
{
    int i=0;
    for(i=0;i<size;i++)
    printf("%d ",arr[i]);
    printf("\n");
}



Related Contents to follow