#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <iomanip>
#include <vector>
#include <string>
usingnamespace std;
void printPascal(int n)
{
constint row;
row = n;
constint col;
col = n;
int list2[row][col];
for (int line = 0; line < n; line++)
{ // number of integers is equal to line number
for (int i = 0; i <= line; i++)
{
if (line == i || i == 0)
list2[line][i] = 1; //first and last value is 1
else
list2[line][i] = list2[line - 1][i - 1] + list2[line - 1][i];
cout << list2[line][i] << " ";
}
cout << "\n";
}
}
int main()
{
int n5;
n5 = 5;
printPascal(n5);
}
I am getting lots of errors for the declertation of list 2:
"Error (active) E0257 const variable "row" requires an initializer"
Same error for column and a few more related to the const variable.
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <iomanip>
#include <vector>
#include <string>
usingnamespace std;
void printPascal(int n)
{
int row = n;
int col = n;
int list2[5][5]; // Created an array size of int n5
// Increase the 5 if you increase n5
for (int line = 0; line < n; line++)
{ // number of integers is equal to line number
string spaces(n-line,' '); // Added spaces to better represent a triangle on screen
cout << spaces;
for (int i = 0; i <= line; i++)
{
if (line == i || i == 0)
list2[line][i] = 1; //first and last value is 1
else
list2[line][i] = list2[line - 1][i - 1] + list2[line - 1][i];
cout << list2[line][i] << " ";
}
cout << "\n";
}
}
int main()
{
int n5 = 5;
printPascal(n5);
}
up to a certain point, pow(11,row) works too :) where row = 0...4.
it stops working when the internals should be double digits (at 5) .. which is bigger than any polynomial I ever needed the coefficients for, so it more or less works for all practical use cases.
(Don't code it like this. Its just a fun math comment -- your professor wants to see the array addition logic).