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

for N<K
NCOMB(N,K)=0 for K<=0

the following formula holds for all integers K


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 = N
do J = N - K + 1 to N - 1; Nom = Nom * J; end
return Nom / FACT(K)



Cover Contents Index Main page Rexx page Mail

last modified 7th July 2014
Copyright 2000-2013 Vladimir Zabrodsky
Czech Republic