Advertisement
dinophanhk

[C] Draw Pascal's triangle

Jun 18th, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | None | 0 0
  1. /*
  2.            1
  3.          1   1
  4.        1   2   1
  5.      1   3   3    1
  6.    1  4    6   4   1
  7.  1  5   10   10  5   1
  8. */
  9.  
  10. #include<stdio.h>
  11. int main()
  12. {
  13.     int rows,coef=1,space,i,j;
  14.     printf("Enter number of rows: ");
  15.     scanf("%d",&rows);
  16.     for(i=0;i<rows;i++)
  17.     {
  18.         for(space=1;space<=rows-i;space++)
  19.         printf("  ");
  20.         for(j=0;j<=i;j++)
  21.         {
  22.             if (j==0||i==0)
  23.                 coef=1;
  24.             else
  25.                coef=coef*(i-j+1)/j;
  26.             printf("%4d",coef);
  27.         }
  28.         printf("\n");
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement