Print Pascal Triangle

[Solved] Print Pascal Triangle | Pascal - Code Explorer | yomemimo.com
Question : print pascal triangle

Answered by : charan-vaddepally

vector<vector<int>> generate(int numRows) { vector<vector<int>> ans; vector<int> first(1,1); ans.push_back(first); int n = numRows; for(int i=1; i<n; i++){ vector<int> second(i+1,0); for(int j=0; j<i+1; j++){ if(j==0 || j==i) second[j] = 1; else{ second[j] = first[j] + first[j-1]; } } ans.push_back(second); first = second; } return ans;
}

Source : | Last Update : Tue, 22 Mar 22

Answers related to print pascal triangle

Code Explorer Popular Question For Pascal