The following method generates the indicated number of rows in Pascal's triangle:
// Make a Pascal's triangle with the desired number of rows.private List<List<int>> MakePascalsTriangle(int numRows){ // Make the result list. List<List<int>> triangle = new List<List<int>>(); // Make the first row. List<int> prevRow = new List<int>(); prevRow.Add(1); triangle.Add(prevRow); // Make the other rows. for (int rowNum = 2; rowNum <= numRows; rowNum++) { // Make the next row. List<int> newRow = new List<int>(); newRow.Add(1); for (int colNum = 2; colNum < rowNum; colNum++) { newRow.Add( prevRow[colNum - 2] + prevRow[colNum - 1]); } newRow.Add(1); // Prepare for the next row. triangle.Add(newRow); prevRow = newRow; } return triangle; ...