
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Maximum binomial coefficient term value in C
We are given with a positive integer ‘N’. We have to find the maximum coefficient term in all binomial coefficients.
The binomial coefficient series is nC0, nC1, nC2, …., nCr, …., nCn-2, nCn-1, nCn
find the maximum value of nCr.
nCr = n! / r! * (n - r)!
Input − N=4
Output − Maximum Coefficient − 6
Explanation − 4C0= 1, 4C1 = 4, 4C2 = 6, 4C3 = 4, 4C4 = 1
Therefore, the maximum coefficient is 6 in this case.
Input − N=5
Output − Maximum Coefficient − 10
Explanation − 5C0= 1, 5C1 = 5, 5C2 =10, 5C3 = 10, 5C4 = 5, 5C5 = 1
Therefore, the maximum coefficient is 10 in this case.
Approach used in the below program is as follows
We take input from the user for N.
Function maxCoeff(int n) takes one parameter ‘n’ and return the maximum coefficient found so far stored in C[n+1][n+1]
Initialize the min and max variables with 0. ‘min’ is used to traverse the C[][] array and ‘max’ is used to store the maximum coefficient value found.
For loop from i=0 to n is used to initialize the C[][] array.
Now inside another for loop traverse till ‘i’ or ‘n’ whichever is minimum.
If i==j. C[i][j]==1. else C[i][j] = C[i-1][j-1] + C[i-1][j];
Now traverse the whole C[][] again and store maximum coefficient in max.
Return the result.
Example
#include <stdio.h> int maxCoeff(int n){ int C[n+1][n+1]; int max=0,min=0; // Calculate value of Binomial Coefficient in for (int i = 0; i <= n; i++){ min=i<n?i:n; for (int j = 0; j <= min; j++){ if (j == 0 || j == i) C[i][j] = 1; else C[i][j] = C[i-1][j-1] + C[i-1][j]; } } for (int i = 0; i <= n; i++){ max = max> C[n][i] ? max: C[n][i]; } return max; } int main(){ int N = 3; printf("Maximum Coefficient :%d", maxCoeff(N) ); return 0; }
Output
If we run the above code it will generate the following output −
Maximum Coefficient: 3
- Related Articles
- Binomial Coefficient in C++
- Binomial Coefficient in java
- How to find the binomial coefficient of two integers using JavaScript?
- Binomial Heap in C++?
- Binomial Random Variables in C++
- Maximum Erasure Value in C++
- Maximum XOR value in matrix in C++
- Memory representation of Binomial Heap in C++
- Maximum of Absolute Value Expression in C++
- C program for Binomial Coefficients table
- Sum of squares of binomial coefficients in C++
- C++ Path with Maximum Average Value
- Get the maximum value in the SortedSet in C#
- Identify the numerical coefficient of the following term$100 m + 1000 n$
- Find sum of even index binomial coefficients in C++
