#include <bits/stdc++.h>
using namespace std;
int fact(int n)
{
if(n<=1) return 1;
return n*fact(n-1);
}
int ncr(int n,int r)
{
return fact(n)/(fact®*fact(n-r));
}
void pascal(int n)
{
if(n == 0) return;
pascal(n-1);
for(int i = 0;i<n;i++)
cout <<" “<< ncr(n-1,i)<<” ";
cout << endl;
}
int main()
{
int n;
cin >> n;
pascal(n);
return 0;
}
my output is coming as
1
1 1
1 2 1
1 3 3 1
but given output is
1
1 1
1 2 1
1 3 3 1
pls tell the mistake
Pascal triangle 1 challenge
pls tell the mistake
Hi @yutikakhanna
You are getting wrong answer because you are not printing spaces before the starting of printing the number. Like in the sample case in the first row 1 is printed after some space and this space keeps on decreasing as we move downward.
Here is your corrected code :