Pascal's triangle: Difference between revisions

Content added Content deleted
(simplified CL program)
Line 133: Line 133:
=={{header|C++}}==
=={{header|C++}}==
<cpp>#include <iostream>
<cpp>#include <iostream>
#include <algorithm>


void genPyrN(int rows) {
void genPyrN(int rows) {
Line 145: Line 146:
int *thisRow = new int[i+1];
int *thisRow = new int[i+1];
thisRow[0] = last[0]; // beginning of row
thisRow[0] = last[0]; // beginning of row
for (int j = 1; j < i; j++) // middle of row
std::transform(&last[0], &last[i], &last[1], &thisRow[1], std::plus<int>()); // middle of row
//sum from the last row
thisRow[j] = last[j-1] + last[j];
thisRow[i] = last[i-1]; // end of row
thisRow[i] = last[i-1]; // end of row