In mathematics combination is formulated with :
C(n,k) = n! / n!* (n-k)!
For example,combination from 5 and 2 is :
C(5,2) = 5! / 5!* (5-2)!
= 10
In pascal programming you can use statement like this to finish it.
program combinasi;uses wincrt;var fn,fk,fn_k,kombinasi : 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;kombinasi:= fn/(fk*fn_k);writeln(n,' kombinasi ',k,' = ',kombinasi:0:0);end.
And the output is like this :
2 comments:
kerennnn...
helpfull. tapi tu intro di atas tentang penjelasan kombinasi perlu diperbaiki. ada sedikit kesalahan..
Post a Comment