# Pascal triangle 1

why my code is not working??
#include
using namespace std;
int main() {
int n;
cin>>n;
for(int i=0;i<n;i++){

for(int j=1;j<n-i;j++){
cout<<' ';
}
long int val=1;
for(int j=0;j<=i;j++){
cout<<val<<' ';
val=(val*(i-j))/(j+1);
}
cout<<endl;
}
return 0;

}

i am unable to understand what is the exact no rows i have to print in every row

hi @rabimajumder08
refer this -->

#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;

for(int i=1;i<=n;i++){
int num=1;
for(int j=1;j<=n-i+1;j++){
cout<<" ";
}

for(int j=1;j<=i;j++){
if(j==1){
cout<<j<<" ";
}
else{
num=num*(i-j+1)/(j-1);
cout<<num<<" ";
}
}
cout<<endl;
}
}

pls explain the no of space in each row

hi @rabimajumder08
As output format is expected, in beginning of each row no is spaces can be calculated by computing the formula

pls explain in1st row how many space are there and what formula r u using

hi @rabimajumder08
suppose our input i.e n is 4â€¦
therefore for first row no of spaces would
=> n - i + 1
=> 4 - 1 + 1 (n is 4, i = 1(ie row number))
=> 4 spaces

Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.