Question: Debug in C++. C++ program to demonstrate a 2D vector where each of its elements is of different size. It builds the famous Pascal's Triangle.
Debug in C++.
C++ program to demonstrate a 2D vector where each of its elements is of different size. It builds the famous Pascal's Triangle.

#include
#include
using namespace std;
int binomialCoeff(int n, int k) {
int res = 1;
if (k > n - k)
k = n - k;
for (int i = 0; i
res *= (n - i);
res /= (i + 1);
}
return res;
}
// read size of triangle from command line argument and convert to an integer
int main(int argc, char *argv[]) {
int numLines = *argv[0];
vector
for (int line = 0; line
vector
for (int row = 0; row
if (row == 0 || row == line)
aRow.push_back(1);
else
aRow.push_back(binomialCoeff(row, line));
}
pascal.push_back(aRow);
}
/* Now we print the vector that we just defined using a simple
range-based for loop. */
for (vector
for (int value : row){
cout
}
cout
}
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
