The Number of Combinations
The combinations of N objects taken K at a time are the possible choices of K different elements from a set of N objects. The number of combinations, which we denote by NCOMB(N,K) is
NCOMB(N,K)=(N*(N-1)*...*(N-K+1))/FACT(K)
NCOMB(N,K)=0 for N<K
NCOMB(N,K)=0 for K<=0
the following formula holds for all integers K NCOMB(N,K)=NCOMB(N,N-K)
IMPLEMENTATION
Unit: internal function, external function without procedure statement
Parameters: integers N>=0,K
Interface:
the FACT function
Returns: the number of combinations NCOMB(N,K)
NCOMB: procedure
parse arg N, K
if K < 0 | N < K then return 0
if K = N then return 1
if K > N - K then K = N - K
Nom = 1
do J = N - K + 1 to N; Nom = Nom * J; end
return Nom / FACT(K)
|
CONNECTIONS
|