PHP gmp_binomial() Function Last Updated : 25 Aug, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report The gmp_binomial() function is an inbuilt function in PHP that is used to calculate the binomial coefficients. The binomial coefficient, often denoted as "n choose k" or "C(n, k)", represents the number of ways to choose "k" elements from a set of "n" distinct elements without regard to the order. Syntax: gmp_binomial(GMP|int|string $n, int $k): GMPParameters: This function accepts two parameters that are described below. $n: This parameter must be an integer.$k: This parameter must be an integer type. If this parameter is negative. It will occur the error.Return Value: The gmp_binomial() function returns the coefficient of the numbers c(n, k) ; Program 1: The following program demonstrates the gmp_binomail() function. PHP <?php // Assuming you have the GMP extension enabled $n = 6 ; $k = 2 ; $binomialCoefficient = gmp_binomial($n, $k); echo "Binomial Coefficient C($n, $k) is: " . $binomialCoefficient . "\n"; ?> Output Binomial Coefficient C(6, 2) is: 15Program 2: The following program demonstrates the gmp_binomail() function. PHP <?php // Assuming gmp library in enable in your PHP try { $n = 5; // Total number of distinct elements $k = -2 ; if($k < 0) { throw new Exception("$k value must be greater than 0") ; } $binomialCoefficient = gmp_binomial($n, $k); echo "Binomial Coefficient C($n, $k) is: " . $binomialCoefficient . "\n"; } catch(Exception $e) { echo $e->getMessage() ; } ?> Output: k value must be greater than 0 Reference: https://www.php.net/manual/en/function.gmp-binomial.php Comment More infoAdvertise with us Next Article PHP gmp_binomial() Function N neeraj3304 Follow Improve Article Tags : PHP PHP-function PHP-gmp Similar Reads PHP | gmp_com() Function The gmp_com() is an inbuilt function in PHP which is used to calculate the one's complement of a GMP number(GNU Multiple Precision : For large numbers). Syntax: gmp_com($num) Parameters: This function accepts a GMP number $num as a mandatory parameter as shown in the above syntax. This parameter can 2 min read PHP | gmp_and() Function The gmp_and() is an inbuilt function in PHP which is used to calculate the bitwise AND of two GMP numbers(GNU Multiple Precision : For large numbers). Syntax: gmp_and($num1, $num2) Parameters: This function accepts two GMP numbers, $num1, $num2 as mandatory parameters as shown in the above syntax. T 2 min read PHP | gmp_cmp() Function The gmp_cmp() is an inbuilt function in PHP which is used to compare two GMP numbers(GNU Multiple Precision : For large numbers). Syntax: gmp_cmp($num1, $num2) Parameters: This function accepts two GMP numbers $num1 and $num2 as mandatory parameters as shown in the above syntax for comparing. These 2 min read PHP | gmp_clrbit() Function The gmp_clrbit() function is an in-built function in PHP which clears a bit of a GMP number (GNU Multiple Precision). The gmp_clrbit() function sets the bit at a specified index in a GMP number to 0. The index starts at zero from the least significant bit. Syntax : gmp_clrbit( $num, $index ) Paramet 2 min read PHP | gmp_or() Function The gmp_or() is an inbuilt function in PHP which is used to calculate the bitwise OR of two GMP numbers(GNU Multiple Precision : For large numbers). Syntax: gmp_or($num1, $num2) Parameters: This function accepts two GMP numbers, $num1, $num2 as mandatory parameters as shown in the above syntax. Thes 2 min read Like