Question
Write a C++ RECURSIVE program according to given function prototype AND MUST PASS ALL TEST CASES Given an array A, make a triangle such that
Write a C++ RECURSIVE program according to given function prototype AND MUST PASS ALL TEST CASES Given an array A, make a triangle such that the bottom most level has all array elements. Then, at each level number of elements is one more than the previous level. Elements at each level is the sum of consecutive elements in the previous level. Function prototype to use : int** sum_of_sequence(int arr,int size) Example : Input: [1.2,3,4,5]
Output: [3,5,7,9]
[8,12,16]
[20,28]
[48]
GOOGLE TEST CASES
TEST(SumofSequence, case1) { int* arr=new int[5]{1,2,3,4,5}; int** a=sum_of_sequence(arr,5); ASSERT_EQ(a[0][0], 3); ASSERT_EQ(a[0][1], 5); ASSERT_EQ(a[0][2], 7); ASSERT_EQ(a[0][3], 9); ASSERT_EQ(a[1][0], 8); ASSERT_EQ(a[1][1], 12); ASSERT_EQ(a[1][2], 16); ASSERT_EQ(a[2][0], 20); ASSERT_EQ(a[2][1], 28); ASSERT_EQ(a[3][0], 48);
}
TEST(SumofSequence, case2) { int* arr=new int[6]{1,2,1,2,1,2}; int** a=sum_of_sequence(arr,6); ASSERT_EQ(a[0][0], 3); ASSERT_EQ(a[0][1], 3); ASSERT_EQ(a[0][2], 3); ASSERT_EQ(a[0][3], 3); ASSERT_EQ(a[0][4], 3); ASSERT_EQ(a[1][0], 6); ASSERT_EQ(a[1][1], 6); ASSERT_EQ(a[1][2], 6); ASSERT_EQ(a[1][3], 6); ASSERT_EQ(a[2][0], 12); ASSERT_EQ(a[2][1], 12); ASSERT_EQ(a[2][2], 12); ASSERT_EQ(a[3][0], 24); ASSERT_EQ(a[3][1], 24); ASSERT_EQ(a[4][0], 48);
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started