Sum Triangle for given array
Submissions: 1323   Accuracy:

37.87%

  Difficulty: Basic   Marks: 1

Given a array, write a program to construct a triangle where last row contains elements of given array, every element of second last row contains sum of below two elements and so on.

Example:
Input: arr[] = {4, 7, 3, 6, 7};
Output:
81
40 41
21 19 22
11 10 9 13
4 7 3 6 7

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains an integer n denoting the size of the array. Then next line contains n space separated integers forming the array.

Output:
Output the sum triangle for the input array with space separated integers.

Constraints:
1<=T<=1000
1<=N<=1000
1<=Ai<=1000

Example:
Input:

2
5
4 7 3 6 7
7
5 8 1 2 4 3 14

Output:
81 40 41 21 19 22 11 10 9 13 4 7 3 6 7 
200 98 102 55 43 59 34 21 22 37 22 12 9 13 24 13 9 3 6 7 17 5 8 1 2 4 3 14 

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Ayush Govil
Author: Ayush Govil 1


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.