123456789101112131415161718192021222324252627282930 |
- #include <stdio.h>
- int main() {
- int n, i, j;
- scanf("%d", &n);
- int triangle[n + 1][n + 1];
- for (i = 0; i <= n; i++) {
- for (j = 0; j <= i; j++) {
- if (j == 0 || j == i)
- triangle[i][j] = 1;
- else
- triangle[i][j] = triangle[i - 1][j - 1] + triangle[i - 1][j];
- }
- }
- int max_width = 4 * triangle[n][n];
- for (i = 0; i <= n; i++) {
- for (j = 0; j < n - i; j++)
- printf("%*s", max_width + 1, "");
- for (j = 0; j <= i; j++)
- printf("%*d", max_width, triangle[i][j]);
- printf("\n");
- }
- return 0;
- }
|