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
- C Program to Print Prime Numbers from 1 to 100
- C Program to Find LCM and GCD of Two Numbers
- C Program to Add Spaces in a String
- C Program To Add Digits Of A Number
- C Program To Find Leap Year
- C Program To Append Data Into A File
- C Program to Accept Only Integer Values
- C Program To Arrange Numbers In Descending Order
- C Program to Add Days to Date
- C Program to Add Two Fractions
- C Program To Reverse A Number
- C Program to Find Maximum and Minimum Numbers
- C Program to Read a Text File
- C Program to Convert Decimal to Hexadecimal
- C Program to Convert Decimal to Binary
- C Program to Convert Celsius to Fahrenheit
- C Program To Find Absolute Value
- Ternary Operator Program in C
- C Program For Addition Table Using For Loop
- Denomination Program in C