fork download
  1.  
  2.  
  3. #include <stdio.h>
  4.  
  5. long factorial(int);
  6.  
  7. int main()
  8. {
  9. int i, n, c;
  10.  
  11. printf("Enter the number of rows you wish to see in pascal triangle\n");
  12. scanf("%d",&n);
  13.  
  14. for (i = 0; i < n; i++)
  15. {
  16. for (c = 0; c <= (n - i - 2); c++)
  17. printf(" ");
  18.  
  19. for (c = 0 ; c <= i; c++)
  20. printf("%ld ",factorial(i)/(factorial(c)*factorial(i-c)));
  21.  
  22. printf("\n");
  23. }
  24.  
  25. return 0;
  26. }
  27.  
  28. long factorial(int n)
  29. {
  30. int c;
  31. long result = 1;
  32.  
  33. for (c = 1; c <= n; c++)
  34. result = result*c;
  35.  
  36. return result;
  37. }
Success #stdin #stdout 0s 3100KB
stdin
7
stdout
Enter the number of rows you wish to see in pascal triangle
      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