In mathematics combination is formulated with :
P(n,k) = n ! / (n-k)!
For example,combination from 5 and 2 is :
P(5,2) = 5 ! / (5-2)!
= 20
In pascal programming you can use statement like this to finish it.
program permutation1;uses wincrt;var fn,fk,fn_k,Permutation : real;i,n,k : integer;beginwrite('input n =');readln(n);write('input k =');readln(k);fn:=1;fk:=1;fn_k:=1;for i:=2 to n dofn := fn * i;for i:=2 to k dofk := fk * i;for i:=2 to (n-k) dofn_k := fn_k * i;permutation:= fn/(fn_k);writeln(n,' Permutation ',k,' = ',Permutation:0:0);end.
and the output is like this :
1 comment:
Your Blog is Fabulous. Good article rather. Very interesting.
Post a Comment