program for pascal traingle in C++.

#include<iostream.h>
class PascalTriangle
{
int i,j,k,r,m,n,p;
int temp,x;
public:
void getinput();
void getpascaltriangle();
int factorial(int);
};
void PascalTriangle::getinput()
{
cout<<"enter no of lines";
cin>>n;
if(n<=0)
cout<<"not possible";
}
void PascalTriangle::getpascaltriangle()
{
for(i=n;i>=1;i--)
{
for(j=1;j<=(i-1);j++)
{
cout<<" ";
}
r=n-i;
for(k=0;k<=r;k++)
{
x=factorial(r)/(factorial(k)*factorial(r-k));
cout<<x;
if(r==k)
cout<<endl;
else
cout<<" ";
}
}
}
int PascalTriangle::factorial(int m)
{
if(m!=0)
{
return m* factorial(m-1);
}
if(m==0)
return 1;
}
main()
{
PascalTriangle P;
P.getinput();
P.getpascaltriangle();
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s