// Cpp program to Find the Nth row in Pascal’s // Triangle using efficient approach…
- User
// Cpp program to Find the Nth row in Pascal’s // Triangle using efficient approach #include <bits/stdc++.h> using namespace std;
// Print the N-th row of the Pascal's Triangle vector generateNthrow(int N) { vector res;
// nC0 = 1 int prev = 1; res.push_back(prev); for (int i = 1; i <= N; i++) { // nCr = (nCr-1 * (n - r + 1))/r int curr = (prev * (N - i + 1)) / i; res.push_back(curr); prev = curr; } return res;}
int main() { int N = 5; vector arr = generateNthrow(N); for(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
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