- 1C Program - Print Simple Pyramid Pattern
- 2C Program - Print Given Triangle
- 3C Program - Print 180° Rotation of Simple Pyramid
- 4C Program - Print Inverted Pyramid
- 5C Program - Print Number Pattern
- 6C Character Pattern Program
- 7C Hollow Star Pyramid Pattern
- 8C Floyd's Triangle Program
- 9C Pascal's Triangle Program
C Program - Print Pascal's Pattern Triangle Pyramid
#include <stdio.h>
long factorial(int n) {
long f = 1;
for(int i = 1; i <= n; i++)
f *= i;
return f;
}
int main() {
int i, j, space, n = 5;
for(i = 0; i < n; i++) {
// Print leading spaces
for(space = 0; space < n - i - 1; space++)
printf(" ");
// Print Pascal's values
for(j = 0; j <= i; j++) {
long val = factorial(i) / (factorial(j) * factorial(i - j));
printf("%4ld", val);
}
printf("\n");
}
return 0;
}
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Comments
Loading comments...