Skip to content

Commit 8d30ebf

Browse files
Merge pull request #47 from softgengaurav/feature_pattern_pascaltriangle
Added CPP File for Pascal Triangle
2 parents 166d773 + 291d803 commit 8d30ebf

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Patterns/PascalsTriangle.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int rows, i, space, k, c = 1;
7+
cout<<"Enter the number of rows to be printed :"<<endl;
8+
scanf("%d", &rows);
9+
for (i = 0; i < rows; i++)
10+
{
11+
for (space = 1; space <= rows - i; space++)
12+
{
13+
cout<<" ";
14+
}
15+
for (k = 0; k <= i; k++)
16+
{
17+
if (k == 0 || i == 0)
18+
{
19+
c = 1;
20+
}
21+
else
22+
{
23+
c = c * (i - k + 1) / k;
24+
}
25+
printf("% 4d", c);
26+
}
27+
28+
cout<<endl;
29+
}
30+
return 0;
31+
}

0 commit comments

Comments
 (0)