Saturday , 11 November 2017
Home » C Programs » C Program to print Pascal Triangle

C Program to print Pascal Triangle

Question:

Write a C program to print Pascal Triangle.

pascal triangleOne of the most interesting Number Patterns is Pascal’s Triangle (named after Blaise Pascal, a famous French Mathematician and Philosopher).

To build the triangle, start with “1” at the top, then continue placing numbers below it in a triangular pattern.¬†Each number is the two numbers above it added together (except for the edges, which are all “1”).

Similar Questions:

1. Pascal triangle in c without using array

2. Pascal triangle in c without using function

3. C code to print Pascal triangle

4. Simple c program for Pascal triangle

5. C program to generate Pascal triangle

6. Pascal triangle program in c language

7. C program to print Pascal triangle using for loop

Programming Code:

/*
 * Program to print Pascal Triangle
 * @author : www.guideforschool.com
 * @Program Type : C Program
 */

#include <stdio.h>
int main(void)
{
    int i,j,n,k,space;
    long c;
    printf("\nEnter no. of lines : ");
    scanf("%d",&n);
    printf("\n");
    space=n;
    for(i=0;i<n;i++)
    {
        c=1;
        for(k=space;k>=0;k--)
        {
            printf("   ");
        }
        space--;
        for(j=0;j<=i;j++)
        {
            printf("%6ld",c);
            c=(c*(i-j)/(j+1));
        }
        printf("\n");
    }
    return 0;
}

Output:

Enter no. of lines : 7

                             1
                          1     1
                       1     2     1
                    1     3     3     1
                 1     4     6     4     1
              1     5    10    10     5     1
           1     6    15    20    15     6     1

Check Also

C Program on Decimal to Hexadecimal Number Conversion

Write a Program in C to input a number in Decimal number system and convert it into its equivalent number in the Hexadecimal number system.

Leave a Reply

Your email address will not be published. Required fields are marked *