forked from ravya1108/hactoberfest2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrint_Pascal_Triangle.cpp
43 lines (43 loc) · 922 Bytes
/
Print_Pascal_Triangle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<iostream>
using namespace std;
int main()
{
int row, col, i=1, j=0, arr[5], arrTemp[5];
arr[0] = 1;
arr[1] = 1;
for(row=0; row<5; row++)
{
for(col=4; col>row; col--)
cout<<" ";
for(col=0; col<=row; col++)
{
if(row==0)
cout<<"1";
else
{
if(col==0 || col==row)
cout<<"1 ";
else
{
arrTemp[i] = arr[j]+arr[j+1];
cout<<arrTemp[i]<<" ";
i++;
j++;
}
}
}
cout<<endl;
arrTemp[i] = 1;
if(row>1)
{
j=0;
arr[j]=1;
for(j=1, i=1; j<=row; j++, i++)
arr[j] = arrTemp[i];
i=1;
j=0;
}
}
cout<<endl;
return 0;
}