o1-mini-2024-09-12· OpenAI
WildChat-4.8M (AI2)
// Cpp program for Pascal’s Triangle Using Dynamic // Programming in O(n^2) time and…
- User
// Cpp program for Pascal’s Triangle Using Dynamic // Programming in O(n^2) time and O(n^2) extra space
#include <bits/stdc++.h> using namespace std;
void printPascal(int n) {
code// An auxiliary array to store // generated pascal triangle values vector<vector<int>> arr(n, vector<int> (n)); // Iterate through every line and // print integer(s) in it for (int row = 0; row < n; row++) { // Every line has number of integers // equal to line number for (int i = 0; i <= row; i++) { // First and last values in every row are 1 if (row == i || i == 0) arr[row][i] = 1; // Other values are sum of values just // above and left of above else arr[row][i] = arr[row - 1][i - 1] + arr[row - 1][i]; cout << arr[row][i] << " "; } cout << endl; }}
int main() { int n = 5; printPascal(n); 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.
If main class is not needed don’t use it like in python and JavaScript
and In C program don’t use #define and malloc and calloc instead use simple array
- Assistant