See the Tutorial List

Program to print Pascal Triangle in C++

Following is the program to print Pascal Triangle.

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

int main()
{
	int n,i,j,c,k,place;
	
	cout<<"Enter the no of rows: "<<endl;
	cin>>n;
	cout<<" \n\nPASCAL TRIANGLE"<<endl;
	cout<<"\n\n";
	place=n;
		for(i=0;i<n;i++){
			c=1;
			for(k=place;k>=0;k--)
				cout<<" ";

				place--;
			for(j=0;j<=i;j++){
					cout<<c<<" ";
					c=(c*(i-j)/(j+1));
				}
			cout<<"\n";

	    }
getch();
return 0;
}

Enter number of rows: 5 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1