Discussion Forums

New User? Please read instructions!

C program to print pascal triangle  

  RSS

thiyagarajan.s
Active Member
Joined: 4 months  ago
Posts: 14
27/01/2017 10:03 am  

C program to print pascal triangle 


ReplyQuote
prakash
Eminent Member
Joined: 4 months  ago
Posts: 20
16/02/2017 1:41 pm  

C program to print pascal triangle:

 

#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;

}

 

long fact(int n)

{

     int c;

     long result = 1;

 

     for( c = 1 ; c <= n ; c++ )

     {

         result = result*c;

     } 

   return ( result );

}

 

Output:

Please enter number of rows you would like to see in pascal triangle

6

Pascal Triangle pattern:

     1 

    1 1 

   1 2 1 

  1 3 3 1 

 1 4 6 4 1 

1 5 10 10 5 1 

 


ReplyQuote
  
Working

Please Login or Register

Ask your questions or clarify your/others doubts from,

✅ Online Discussion Forums by Fresh2Refresh.com





Share this website !!!
Facebook Twitter Linkedin

Close
We Support JALLIKATTU !!!
We Support JALLIKATTU!
By Fresh2Refresh.com
Show Your Support as well. Thanks!