TheFestFever.com

Our aim is to connect students from campuses all over Delhi by making them aware of all Technical, Cultural, Management fests, workshops, Seminars organized by every college in Delhi.

Join Us Now

Program 20: Write a C++ program to print Pascal’s triangle.

#include<iostream>
using namespace std;

int main()
{
	int i,row,j,space,coef=1;
	cout<<"\nenter number of rows : ";
	cin>>row;
	cout<<"\nPascal's Triangle : ";

	for(i=0;i<row;i++)
	{
		cout<<"\n";
		for(space=1;space<=row-i;space++)
		cout<<" ";

		for(j=0;j<=i;j++)
		{
			if(j==0||i==0)
			coef=1;
			else
			coef=coef*(i-j+1)/j;
			cout<<" "<<coef;
		}
	}
	return 0;
}



If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.