fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int rows, coef = 1, space, i, j;
  5.  
  6. printf("Enter the number of rows: ");
  7. scanf("%d", &rows);
  8.  
  9. for (i = 0; i < rows; i++) {
  10. // Print spaces for alignment
  11. for (space = 1; space <= rows - i; space++)
  12. printf(" ");
  13.  
  14. for (j = 0; j <= i; j++) {
  15. if (j == 0 || i == 0)
  16. coef = 1;
  17. else
  18. coef = coef * (i - j + 1) / j;
  19.  
  20. printf("%4d", coef);
  21. }
  22. printf("\n");
  23. }
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 5320KB
stdin
22
stdout
Enter the number of rows:                                                1
                                             1   1
                                           1   2   1
                                         1   3   3   1
                                       1   4   6   4   1
                                     1   5  10  10   5   1
                                   1   6  15  20  15   6   1
                                 1   7  21  35  35  21   7   1
                               1   8  28  56  70  56  28   8   1
                             1   9  36  84 126 126  84  36   9   1
                           1  10  45 120 210 252 210 120  45  10   1
                         1  11  55 165 330 462 462 330 165  55  11   1
                       1  12  66 220 495 792 924 792 495 220  66  12   1
                     1  13  78 286 7151287171617161287 715 286  78  13   1
                   1  14  91 3641001200230033432300320021001 364  91  14   1
                 1  15 105 45513653003500564356435500530031365 455 105  15   1
               1  16 120 560182043688008114401287011440800843681820 560 120  16   1
             1  17 136 6802380618812376194482431024310194481237661882380 680 136  17   1
           1  18 153 816306085681856431824437584862043758318241856485683060 816 153  18   1
         1  19 171 9693876116282713250388755829237892378755825038827132116283876 969 171  19   1
       1  20 1901140484515504387607752012597016796018475616796012597077520387601550448451140 190  20   1
     1  21 210133059852034954264116280203490293930352716352716293930203490116280542642034959851330 210  21   1