Discussion About Pascal Triangle 1

This is Discussion thread about Pascal Triangle 1

#include <iostream>
#include <string>
using namespace std;
void PascalsTriangle(int);

int main()
{
    int n;
    cout << "Enter the number of rows you would like to print for Pascal's Triangle: ";
    cin >> n;
    cout << endl;
    PascalsTriangle(n);
    return 0;
}

int numdigits(int x)
{
    int count = 0;
    while(x != 0) {
        x = x / 10;
        ++count;
    }
    return count;
}

void PascalsTriangle (int n)
{
    int i, j, x, y, maxlen;
    string len;
    for(i = 0; i < n; i++) {
        x = 1;
        len = string((n-i-1)*(n/2), ' ');
        cout << len;
        for(j = 0; j <= i; j++) {
            y = x;
            x = x * (i - j) / (j + 1);
            maxlen = numdigits(x) - 1;
            if(n % 2 == 0)
                cout << y << string(n - 1 - maxlen, ' ');
            else {
                cout << y << string(n - 2 - maxlen, ' ');
            }
        }
        cout << endl;
    } 
}

i applied this code in pascal triangle it is compiling successfully but not sumbiting this answer

Can someone please check this code for pascal triangle. I was getting correct output , but not able to submit code. It’s saying ‘wrong answer’

n=int(input())
h=((n-1)*2)+1
l=[]
for i in range(n):
l.append([’ ']*h)
p=2
l[0][n-1]=1
for i in range(1,n,1):
j=(n-1)-i
l[i][j]=1
l[i][j+p]=1
p=p+2
j=j+2
while l[i][j]!=1:
l[i][j]=l[i-1][j-1]+l[i-1][j+1]
j=j+2

for i in l:
for j in i:
print(j,sep=’ ‘,end=’’)
print()