Skip to content
Home » C Programs » Pascal Triangle in C Using Only For Loop

Pascal Triangle in C Using Only For Loop

Simple pascal triangle code in c programming language for beginners. Using this programming language you can learn how to use coef in programs and looping statement in c.

coef in C

A coefficient is a multiplicative factor in a polynomial, a series, or any expression in mathematics; it is usually a number, although it can be any expression. The coefficients are frequently referred to as parameters when they are variables. 

A constant factor of a term, as opposed to a variable, is one of the elements of a product that is considered in relation to a specific factor. When you multiply a number by a variable, the result is a coefficient. Using this coef we have executed this program pascal triangle code in c

Return Statement in C

A return statement marks the end of a function’s execution and hands control back to the calling function. The calling function continues execution at the place where the call was made. A return statement can give the caller function a value. 

The return statement marks the end of a function’s execution and hands control back to the calling function. The calling function continues execution at the place where the call was made. The calling function can also get a value via a return statement. 

Pascal Triangle Code in C

//pascal triangle code in c
#include <stdio.h>
int main() 
{
int lines, coef = 1, space, i, j;
printf("Enter no of lines ");
scanf("%d", &lines);
for (i = 0; i < lines; i++) 
{
for (space = 1; space <= lines - i; space++)
printf(" ");
for (j = 0; j <= i; j++) 
{
if (j == 0 || i == 0)
coef = 1;
else
coef = coef * (i - j + 1) / j;
printf("%4d", coef);
}
printf("\n");
}
return 0;
}

Output of pascal triangle code in c:

Enter no of lines 5
      1
    1 1
  1 2 1
 1 3 3 1
1 4 6 4 1