In this tutorial, we will discuss the concept of Pascal Triangle program in C++ language
In this topic, we are going to learn how to write a program to print Pascal triangle pattern using number in C++ programming language
Here, we use for, while and do-while loops for printing pascal triangle
Pascal Triangle program
Display pascal pattern in C++ using loops
understanding Pascal Triangle
C++ Code display triangle using for loop
In this program, the user is asked to enter number of rows and then it will display triangle number pattern using for loop in C++ language
Program 1
#include
#include
using namespace std;
int main()
{
int rows,i,j,space,counter=1;
cout>rows;
//input rows for print pascal triangle
for( i=0; i
When the above code is executed, it produces the following result
Triangle program
C++ Code display triangle using while loop
In this program, the user is asked to enter the number of rows and then it will display a triangle number pattern using the while loop in the C++ language
Program 2
#include
#include
using namespace std;
int main()
{
int rows,i,j,space,counter=1;
cout>rows;
//input number of rows for print pascal triangle
i=0;
while(i
When the above code is executed, it produces the following result
Triangle program
C++ Code displays triangle using a do-while loop
In this program, the user is asked to enter a number of rows and then it will display a triangle number pattern using the do-while loop in C++ language
Program 3
#include
#include
using namespace std;
int main()
{
int rows,i,j,space,counter=1;
cout>rows;//input number of rows for print pascal triangle
i=0;
do{//outer do while loop
space=1;
do{//inner do-while loop
cout
When the above code is executed, it produces the following result
1 Comment
aaa September 12, 2022 at 8:54 pm