There are following rules must be made –

- Using 2-D array we can generate the Pascal’s triangle.
- The element at first column (Column Zero) must be filled up with one.
- The element which correspond to the same row and column will be filled up with one.
- Rest of the elements will be filled up with adding the elements of previous row as –

**a[i][j]=a[i-1][j-1] + a[i-1][j];**

#include<iostream.h>
#include<conio.h>
void main()
{
int a[10][10],i,j,n;
clrscr();
cout<<"Enter The Number of Lines : ";
cin>>n;
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
if((j==0) || (j==i))
{
a[i][j]=1;
}
else
{
a[i][j]=a[i-1][j-1] + a[i-1][j];
}
}
}
cout<<"\nThe Pascal's Trianlge is : \n\n";
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
getch();
}

### Like this:

Like Loading...

*Related*