// Cpp program to Find the Nth row in // Pascal’s Triangle using Recursion #include…
- User
// Cpp program to Find the Nth row in // Pascal’s Triangle using Recursion #include <bits/stdc++.h> using namespace std;
// Function to find the elements // of rowIndex in Pascal's Triangle vector getRow(int rowIndex) { vector cur;
code// 1st element of every row is 1 cur.push_back(1); // Check if the row that has to // be returned is the first row if (rowIndex == 0) { return cur; } // Generate the previous row vector<int> prev = getRow(rowIndex - 1); for(int i = 1; i < prev.size(); i++) { // Generate the elements of the current // row by the help of the previous row int curr = prev[i - 1] + prev[i]; cur.push_back(curr); } cur.push_back(1); // Return the row return cur;}
int main() { int n = 3; vector arr = getRow(n);
codefor(int i = 0; i < arr.size(); i++) { if (i == arr.size() - 1) cout << arr[i]; else cout << arr[i] << ", "; } return 0;}
Give me code in Python, Java, C#, JavaScript and C
Remember like Cpp is for C++ and at start replace Cpp with language name and then comment
without changing variable name and also do not change comments
have one line space after code when comment is written.
don’t use class if needed then name it GfG
don’t use public if not needed.
and In C program don’t use #define and malloc and calloc instead use simple array
- Assistant