I am trying to write a pascal triangle. I finished the code and try to test on site but it showed output is wrong. I tried to do on VS and it worked. Is that a site problem or is there a problem with my code?
#include <iostream>
using namespace std;
void printPascalTr(int size) { //define your function
int const size1 = size;
int Pascal[size1][size1] = { {1},{1,1} };
for (int i = 2; size1 > i; i++) {
for (int j = 0; size1 > j; j++) {
if (j == 0 ) {
Pascal[i][j] = 1;
cout << Pascal[i][j] << " ";
}
else {
Pascal[i][j] = Pascal[i - 1][j - 1] + Pascal[i - 1][j];
}
}
cout << "\n";
}
for (int h = 0; h < size1; h++)
{
for (int k = 0; k < size1; k++)
{
if (Pascal[h][k] == 0) {
}
else {
cout << Pascal[h][k] <<" ";
}
}
cout << "\n ";
}
}
Course: Learn C++ from Scratch - Free Interactive Course
Lesson: Exercise 4: Pascal Triangle - Learn C++ from Scratch