C Program To Print Pascal Triangle

C Program To Print Pascal Triangle. If you are looking for C Program for Pascal Triangle, here in this tutorial we will help you to learn how to write a C program to display Pascal triangle.

C Program to Print Pascal Triangle

Learn how to write a C program to print Pascal Triangle. Writing a Pascal Triangle C program can be done using various techniques but here in this program, we show how to write a pascal triangle logic in a proper way.

Pascal Triangle Example

           1
         1   1
       1   2   1
     1   3   3    1
   1  4    6   4   1
 1  5   10   10  5   1 

C Program to Print Pascal Triangle Source Code

/* C Program to print pascal traiangle - PascalTriangle.C */

#include <stdio.h>
int main()
{
//variable declaration
 int rows, coef = 1, space, i, j;

//asking user to enter number of rows and reading
printf("Enter number of rows: ");
 scanf("%d",&rows);

//logic for printing pascal triangle
for(i=0; i<rows; i++)
 {
 for(space=1; space <= rows-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;
}

C Program to Print Pascal Triangle Output

Enter number of rows: 6


           1
         1   1
       1   2   1
     1   3   3    1
   1  4    6   4   1
 1  5   10   10  5   1 

C PROGRAMMING TUTORIALS

  1. C Program to Print Prime Numbers from 1 to 100
  2. C Program to Find LCM and GCD of Two Numbers
  3. C Program to Add Spaces in a String
  4. C Program To Add Digits Of A Number
  5. C Program To Find Leap Year
  6. C Program To Append Data Into A File
  7. C Program to Accept Only Integer Values
  8. C Program To Arrange Numbers In Descending Order
  9. C Program to Add Days to Date
  10. C Program to Add Two Fractions
  11. C Program To Reverse A Number
  12. C Program to Find Maximum and Minimum Numbers
  13. C Program to Read a Text File
  14. C Program to Convert Decimal to Hexadecimal
  15. C Program to Convert Decimal to Binary
  16. C Program to Convert Celsius to Fahrenheit
  17. C Program To Find Absolute Value
  18. Ternary Operator Program in C
  19. C Program For Addition Table Using For Loop
  20. Denomination Program in C

Leave a Comment