Pascal Triangle in C || Patterns || C programming
In this, we are going to see a program in which we will print the pattern of Pascal's Triangle as shown in the image above in C programming Language.

//WAP to create Pascal's Triangle Pattern

#include <stdio.h>

void main()
{
    int n, coef = 1, space, i, j;
    printf("Enter the number of Rows: ");
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        for (space = 1; space <= n - i; space++)
        {
            printf("  ");
        }
        for (j = 0; j <= i; j++)
        {
            if (j == 0 || i == 0)
            {
                coef = 1;
            }
            else
            {
                coef = coef * (i - j + 1) / j;
            }
            printf("%4d", coef);
        }
        printf("\n");
    }
}


#ENJOY CODING


2 Comments

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

  1. Need a pyramid with * symbol

    ReplyDelete
    Replies
    1. https://www.helpforcoders.com/2021/07/pyramid-pattern-type-1.html

      It has the code, just instead of # print * in printf statement

      Delete

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post