I am supposed to write a program to output Pascal’s Triangle. Ask the user to input the number of rows of the triangle to display. Also output for each row, the sum of the elements of the row, and show that it is equal to 2n, where n is the row number (with 0 being the first row).
This is what i have so far and my program compile but it just crashes before running. Can anyone help me please
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
cout << "Please enter the number of rows of the triangle to display cn: ";
int cn;
cin>> cn;
int M [cn][cn];
M [0][0] = 1;
for (int i = 1; i < cn+1; i++) M [0] [i] = 0;
M [1] [0] = 1;
M [1] [1] = 1;
for (int j = 2; j < cn+1; j++) M [1] [j] = 0;
for (int k = 2; k < cn+1; k++){
for (int l = 1; l < cn+1; l++)
{
int n = 1;
if(l == 0) M[k][l]= 1;
else M[k][l]= M[k-1][l]+M[k-1][l-1];
}}
for (int p = 0; p < cn+1; p++) {
for (int q = 0; q < cn+1; q++)
cout << M [p][q]<< endl;}
system("Pause");
}