PHP - gmp_binomial() Function
Definition and Usage
The gmp_binomial() function calculates the binomial coefficient .
Description
gmp_binomial() calculates binomial coefficient given as C(n, k) .
Syntax
gmp_binomial ( mixed $num1 , int $k ) : GMP
Parameters
| Sr.No | Parameter & Description |
|---|---|
| 1 |
num1 It can a GMP resource number , a gmp object or a numeric string . |
| 2 |
k number of combinations. |
Return Values
PHP gmp_binomial() function returns a GMP number that is a binomial coefficient.
PHP Version
This function will work from PHP Version greater than 7.3.0.
Example 1
Working of gmp_and −
<?php
$num1 = gmp_binomial('4',2);
echo "The binomial coefficient of (4,2) is ".$num1;
echo "<br/><br/>";
$num2 = gmp_binomial('5',2);
echo "The binomial coefficient of (5, 2) is ".$num2;
?>
This will produce following result −
The binomial coefficient of (4,2) is 6 The binomial coefficient of (5, 2) is 10
Example 2
Using GMP numbers −
<?php $num1 = gmp_init(4); $num2 = gmp_binomial($num1,2); echo "The binomial coefficient of (4,2) is ".$num2; ?>
This will produce following result −
The binomial coefficient of (4,2) is 6
php_function_reference.htm
Advertisements