Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How can I do that using C programming language

+2 votes
asked Apr 1, 2019 by anonymous
I want a code to do Pascal triangle pattern but with even numbers only

1 Answer

0 votes
answered Apr 9 by Bhavanithra Mani (180 points)
#include <stdio.h>

int main() {
    int n;

    printf("Enter the number of rows: ");
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        // Print leading spaces for triangle alignment
        for (int j = 0; j < n - i - 1; j++) {
            printf("  ");
        }

        int val = 1; // first value in the row
        for (int j = 0; j <= i; j++) {
            // Print the value only if it's even, else print space
            if (val % 2 == 0)
                printf("%4d", val);
            else
                printf("    "); // space to maintain alignment

            // Calculate next value in row using Pascal's formula
            val = val * (i - j) / (j + 1);
        }
        printf("\n");
    }

    return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...