C++ Program to Print Pascal Triangle

« Previous Program Next Program »

Print Pascal Triangle in C++

To print pascal triangle in C++ programming, you have to ask to the user to enter the number of line (upto which he/she want to print pascal triangle).

So to print pascal triangle, you have to use three for loops as shown here in the following program.

C++ Programming Code to Print Pascal Triangle

Following C++ program ask to the user to enter number of line or row upto which the Pascal triangle will be printed to print the Pascal triangle and display it on the screen:

/* C++ Program - Print Pascal Triangle */
long fact(int);
void main()
	int i, n, c;
	cout<<"Upto how many line (Enter number of rows) : ";
	for(i=0; i<n; i++)
		for(c=0; c<=(n-i-2); c++)
			cout<<" ";
		for(c=0; c<=i; c++)
			cout<<" ";

long fact(int n)
	int c;
	long res=1;
	for(c=1; c<=n; c++)
		res = res*c;
	return (res);

When the above C++ program is compile and executed, it will produce the following result:

C++ program print pascal triangle

Program Video with Compile and Run

Same Program in Other Language

You may like the same program in other programming languages:

« Previous Program Next Program »


Quick Links
Signup - Login - Give Online Test