[Solved] Finding maximum sum possible of two numbers in array


As per assuming few conditions like provided array size and array data type to be integer you can use the following program for reference.
This program takes the no. of elements and array as input.

#include<stdio.h>
#include<limits.h>

int main(){

    int n;
    int a[100];
    printf("Size of the array:");
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        printf("Enter array element a[%d]:", i);
        scanf("%d", &a[i]);
        printf("\n");
    }

    int max = INT_MIN;
    int sum = 0, k = 0, l = 0;
    for(int i = 0; i < n-2; i++){
        sum = a[i] + a[i+2];
        if(max < sum){
            max = sum;
            k = i;
            l = i+2;
        }
    }
    printf("max sum is: %d using index: a[%d] and a[%d]\n", max, k, l);
}

INPUT

5

-1 7 8 -5 4

OUTPUT

max sum is: 12 using index: a[2] and a[4]

2

solved Finding maximum sum possible of two numbers in array