Skip to content

Commit be5dadc

Browse files
added pascal_triangle.cpp
1 parent f9fb58f commit be5dadc

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

strings/pascal_triangle.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include<iostream>
2+
#include<string>
3+
using namespace std;
4+
5+
int factorial(int x){
6+
if(x==0){
7+
return 1;
8+
}
9+
return x*factorial(x-1);
10+
}
11+
int binomial(int n,int k){
12+
return factorial(n)/(factorial(n-k)*factorial(k));
13+
}
14+
int main(){
15+
int height=0;
16+
cout<<"Enter the height of the triangle:";
17+
cin>>height;
18+
for(int i=0;i<height;i++){
19+
for(int j=0;j<height-i-1;j++){
20+
cout<<" ";
21+
}
22+
for(int j=0;j<=i;j++){
23+
cout<<binomial(i,j)<<" ";
24+
}
25+
cout<<endl;
26+
}
27+
return 0;
28+
}

0 commit comments

Comments
 (0)