Print Pascal Triangle in C++

Advertisements

Prev Tutorial Next Tutorial

C++ Program to Print Pascal Triangle

Pascal's triangle is a triangular array of the binomial coefficients.

triangle triangle

Example

#include<iostream.h>
#include<conio.h>

void main()
{
int bin,p,q,r,x;
clrscr();
bin=1;
q=0;
cout<<"\t\t\tDisplay pascal Triangle";
cout<<"\n\n\t\t     Created By:- Hitesh Kumar";
cout<<"\n\n\nHow Many Row Do you want to input:";
cin<<r;

cout<<"\nPascal's Triangle:\n";

while(q<r)
{
for(p=40-3*q;p>0;--p)
cout<<" ";
for(x=0;x<=q;++x)
{
if((x==0)||(q==0))
bin=1;
else
bin=(bin*(q-x+1))/x;
cout<<"      ";
cout<<bin;
}

cout<<"\n\n\n";
++q;
}
getch();
}

Output

print pascal triangle
Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements