write a c program to print the pascal triangle as shown below


Pascal triangle  

a triangular arrangement of numbers that gives the coefficients in the expansion of any binomial expression, such as (x + y) n. let's see the program to be more clear about this,  

 

Program 

QUESTION:- write a c program to print the pascal triangle as shown below. 

                            1  

                       1         1 

                    1       2        1 

                 1     3       3         1 

              1     4      6        4        1 


 

#include <stdio.h>

#include <conio.h>

void main()

{

    int rowcolspacenoli;

    printf("enter a valuento print pascal triangle: ");

    scanf("%d", &li);

    // rows

    for (row = 0row <= lirow++)

    {

        // space

        for (space = 0space <= (li - row); space++)

        {

            printf(" ");
        }

        no = 1;

        // pascal triangle

        for (col = 0col <= rowcol++)

        {

            printf("%d "no);

            no = no * (row - col) / (col + 1);
        }

        printf("\n");
    }

    getch();
}


OUTPUT

enter a valuento print pascal triangle: 5

      1 

     1 1

    1 2 1

   1 3 3 1

  1 4 6 4 1

 1 5 10 10 5 1


Follow our page for regular updates.

0 Comments