-->

Friday, 10 March 2017

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 

keep calm and say bujuku bujuku.

0 comments:

Post a Comment

Start Work With Me

Contact Us
KUTTY SELVA
+91 7708139984
Madurai,Tamilnadu