Reversed Sum of Pairs

 Coding Problem Keys 

 Reversed Sum of Pairs 

 Problem Statement 

An array of N integers is passed as input. The program must print the sum of every two consecutive elements in the array from last.

 Boundary Condition(s) 

1 <= N <= 1000

 Input Format 

The first line contains N.
The second line contains N integers separated by space(s).

 Output Format 

The first line contains the sum of pairs separated by a space.

 Example Input/Output 1 

 Input 

4
10 50 30 60

 Output 

90 60

 Example Input/Output 2 

 Input 

5
25 50 100 250 300

 Output 

550 150 25

 Note: Max Execution Time Limit: 5000 millisecs 

 Solution 

 Programming Language: C Language 

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

int main() {
    int n,i;
    scanf("%d",&n);
    int arr[n];
    for(int i=0;i<n;i++){
        scanf("%d",&arr[i]);
    }
    for(int i=n-1;i>=0;i-=2){
        if(i==0){
            printf("%d",arr[i]);
            break;
        }
        printf("%d ",arr[i]+arr[i-1]);
    }
}

// Published By PKJCODERS

 (Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.) 

Comments

Popular Posts

Toggle Consonants Adjacent to Vowels

String Pattern - Inverted U

Top Scoring Batsman - TEST ODI 20-20

Desktop Products

Mango Distribution

Java - Method Overriding - Area

Microsoft