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. 

Debug in C++. C++ program to demonstrate a 2D vector where each

#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> pascal;

for (int line = 0; line

vector aRow;

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 row : pascal){

for (int value : row){

cout

}

cout

}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!