Here, we use for, while, and do-while loops for printing pascal triangle
Print Pascal Triangle
Display the pascal triangle in C using loops
Pascal Triangle in Java
C Code to display pascal triangle using for loop
In this program, the user declares and initializes integer variables, it will display a pascal triangle number pattern usingfor loop in the C language according to the rows
Program 1
#include
#include
int main()
{
int arr[30],arrTemp[30],i,j,k,l, rows=5;
arrTemp[0]=1;
arr[0]=1;
for(j=0; j
When the above code is executed, it produces the following result
Output 1
C Code to display pascal triangle using while loop
In this program, the user declares and initializes integer variables, it will display a pascal triangle number pattern using while loop in the C language according to the rows
Program 1
#include
#include
int main()
{
int arr[30],arrTemp[30];
//declare two one dim arrays
int i,j,k,l, rowNo=4;
//declare and initialize
arrTemp[0]=1;
arr[0]=1;
//initialize array elements
j=0;
while(j
When the above code is executed, it produces the following result
Output 2
C Code to display pascal triangle using do-while loop
In this program, the user declares and initializes integer variables, it will display a pascal triangle number pattern using do-while loop in the C language according to the rows
Program 1
#include
#include
int main()
{
int arr[30],arrTemp[30];
//declare two one dim arrays
int i,j,k,l, rowNo=5;
//declare and initialize
arrTemp[0]=1;
arr[0]=1;
//initialize array elements
j=0;
do{
printf(" ");
j++;
} while(j
When the above code is executed, it produces the following result