C Program to a print pascal triangle


This content was proof-read by Grammarly. You can Try Grammary for FREE

Problem Statement

Write a program in C to print pascal triangle.

How to print a pascal triange in C ?

#include <stdio.h> 
long fact(int); 
  
int main() 
{ 
     int n, i, j; 
     printf("Please enter number of rows you would like to see in pascal triangle\n"); 
     scanf("%d",&n); 
    
     printf("Pascal Triangle pattern:\n"); 
  
     for ( i = 0 ; i < n ; i++ ) 
     { 
          for ( j = 0 ; j <= ( n - i - 2 ) ; j++ ) 
          printf(" "); 
  
          for( j = 0 ; j <= i ; j++ ) 
          printf("%ld ",fact(i)/(fact(j)*fact(i-j))); 
  
          printf("\n"); 
     } 
  
     return 0; 
} 
Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

%d bloggers like this: