C program for Binomial Coefficients table

Given with a positive integer value let's say 'val' and the task is to print the value of binomial coefficient B(n, k) where, n and k be any value between 0 to val and hence display the result.

What is Binomial Coefficient

Binomial coefficient (n, k) is the order of choosing 'k' results from the given 'n' possibilities. The value of binomial coefficient of positive n and k is given by −

Syntax

C(n, k) = n! / (k! * (n-k)!)

where, n >= k

Example of Binomial Coefficient Calculation

For B(9,2) −

B(9,2) = 9! / ((9-2)! * 2!)
       = 9! / (7! * 2!)
       = (9 * 8) / (2 * 1)
       = 72 / 2
       = 36

What is Binomial Coefficient Table

The Binomial Coefficient Table displays Pascal's triangle, showing all binomial coefficient values for n from 0 to a given value. Each row represents coefficients for a specific n value.

Binomial Coefficient Table (Pascal's Triangle) n=0: 1 n=1: 1 1 n=2: 1 2 1 n=3: 1 3 3 1 n=4: 1 4 6 4 1 n=5: 1 5 10 10 5 1

Approach

  • Input the variable 'val' from the user for generating the table
  • Start the loop from 0 to 'val' because the value of binomial coefficient will lie between 0 to 'val'
  • Apply the formula: B(n, k) = B(n, k-1) * (n - k + 1) / k
  • Print the result in tabular format

Example

#include <stdio.h>

// Function for binomial coefficient table
void bin_table(int val) {
    for (int i = 0; i <= val; i++) {
        printf("%2d: ", i);
        int num = 1;
        for (int j = 0; j <= i; j++) {
            if (i != 0 && j != 0)
                num = num * (i - j + 1) / j;
            printf("%4d", num);
        }
        printf("<br>");
    }
}

int main() {
    int value = 5;
    printf("Binomial Coefficient Table for n = %d<br><br>", value);
    bin_table(value);
    return 0;
}
Binomial Coefficient Table for n = 5

 0:    1
 1:    1   1
 2:    1   2   1
 3:    1   3   3   1
 4:    1   4   6   4   1
 5:    1   5  10  10   5   1

Key Points

  • The first and last elements in each row are always 1
  • Each element is the sum of the two elements above it in the previous row
  • Row n contains n+1 elements representing C(n,0) to C(n,n)

Conclusion

The binomial coefficient table generates Pascal's triangle efficiently using the multiplicative formula. This approach avoids computing large factorials and provides an elegant way to display all binomial coefficients up to a given value.

Updated on: 2026-03-15T12:25:55+05:30

8K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements