• ## Discover

1. Home >
2. All Categories >
3. Computers & Internet >
4. Programming & Design >
5. Resolved Question
Member since:
30 September 2007
Total points:
106 (Level 1)

## Resolved Question

Show me another »

# Program to display Pascal triangle in C++?

C++ is a computer language
by krishna
Member since:
01 March 2006
Total points:
4,448 (Level 4)

## Best Answer - Chosen by Voters

#include<iostream.h>
void main()
{
int a[10][10],i,j,n;
cout<<" Enter the final row of Pascal's triangle:";
cin>>n;
for(int i=0;i<n;i++)
{ a[i][0]=1;}
for(i=1;i<=n;i++)
{ a[i][i+1]=1;}
for(int i=2;i<n;i++)
{
for(j=1;j<=i;j++)
{
a[i][j]=a[i-1][j-1]+a[i-1]a[j];
}
}
for(i=0;i<n;i++)
{
for(j=0;j<i+1;j++)
{
cout<<a[i][j]<<"\t";
}
cout<<endl;
}

I have used a bi-directional array for this. if you want its explaination, i can explain it to you on patnikrishna@yahoo.co.in
This best answer helped my with my C++ program. To print out a program out to any value i wanted. It really blows up after like 10 but it works. Good job with the double array!

THANK YOU,
Mike

Report Abuse

Really very very helpful ...!!!!!!!!!!great logic....keep it up..!!!!!!!

Report Abuse

• by Pashya
Member since:
29 September 2007
Total points:
1,640 (Level 3)
#include <iostream>
using namespace std;
int main()
{
int n,k,i,x;
cout << "Enter a row number for Pascal's Triangle: ";
cin >> n;
for(i=0;i<=n;i++)
{
x=1;
for(k=0;k<=i;k++)
{
cout << x << " ";
x = x * (i - k) / (k + 1);
}
cout << endl;
}
return 0;
}

### Source(s):

33% 1 Vote
• 2 people rated this as good