From cf5dd0fd173d99c88b9b03d55b3aec421b46294f Mon Sep 17 00:00:00 2001 From: Paridhi Jain <18ec.paridhijain@gmail.com> Date: Sat, 6 Mar 2021 10:48:48 +0530 Subject: [PATCH 1/2] Create Sum of triangular array --- Recursion/C++/Sum of triangular array | 48 +++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Recursion/C++/Sum of triangular array diff --git a/Recursion/C++/Sum of triangular array b/Recursion/C++/Sum of triangular array new file mode 100644 index 00000000..e2997a65 --- /dev/null +++ b/Recursion/C++/Sum of triangular array @@ -0,0 +1,48 @@ +// C++ program to create Special triangle. +#include +using namespace std; + +// Function to generate Special Triangle +void printTriangle(int A[] , int n) + { + // Base case + if (n < 1) + return; + + // Creating new array which contains the + // Sum of consecutive elements in + // the array passes as parameter. + int temp[n - 1]; + for (int i = 0; i < n - 1; i++) + { + int x = A[i] + A[i + 1]; + temp[i] = x; + } + + // Make a recursive call and pass + // the newly created array + printTriangle(temp, n - 1); + + // Print current array in the end so + // that smaller arrays are printed first + for (int i = 0; i < n ; i++) + { + if(i == n - 1) + cout << A[i] << " "; + else + cout << A[i] << ", "; + } + + cout << endl; + } + + // Driver function + int main() + { + int A[] = { 1, 2, 3, 4, 5 }; + int n = sizeof(A) / sizeof(A[0]); + + printTriangle(A, n); + } + +// This code is contributed by Smitha Dinesh Semwal From be208e4db324b7d4f06b1bc204904210c5daf3ec Mon Sep 17 00:00:00 2001 From: Paridhi Jain <18ec.paridhijain@gmail.com> Date: Sun, 14 Mar 2021 19:03:38 +0530 Subject: [PATCH 2/2] Rename Sum of triangular array to Sum_of_triangular_array.cpp --- .../C++/{Sum of triangular array => Sum_of_triangular_array.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Recursion/C++/{Sum of triangular array => Sum_of_triangular_array.cpp} (100%) diff --git a/Recursion/C++/Sum of triangular array b/Recursion/C++/Sum_of_triangular_array.cpp similarity index 100% rename from Recursion/C++/Sum of triangular array rename to Recursion/C++/Sum_of_triangular_array.cpp