C Program To Print Pascal Triangle

Introduction
  • In this blog, I am going to explain how to print a Pascal triangle.
Software Requirements
  • Turbo C++ or C. 
Programming 
  1. #include < stdio.h >   
  2. long factorial(int);  
  3. int main()  
  4. {  
  5.     int i, n, c;  
  6.     printf("Enter the number of rows you wish to see in pascal triangle\n");  
  7.     scanf("%d", & n);  
  8.     for (i = 0; i < n; i++) {  
  9.         for (c = 0; c <= (n - i - 2); c++) printf(" ");  
  10.         for (c = 0; c <= i; c++) printf("%ld ", factorial(i) / (factorial(c) * factorial(i - c)));  
  11.         printf("\n");  
  12.     }  
  13.     return 0;  
  14. }  
  15. long factorial(int n) {  
  16.     int c;  
  17.     long result = 1;  
  18.     for (c = 1; c <= n; c++) result = result * c;  
  19.     return result;  
  20. }  
Explanation
  • With the help of programming given above, Pascal triangle can be printed by giving the number of rows by the user.

    programming

    programming
Output

Output
Next Recommended Reading Print Alternate Elements In An Array