Wednesday, March 25, 2009

Permutation

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;
begin
write('input n =');readln(n);
write('input k =');readln(k);
fn:=1;
fk:=1;
fn_k:=1;
for i:=2 to n do
 fn := fn * i;
for i:=2 to k do
 fk := fk * i;
for i:=2 to (n-k) do
 fn_k := fn_k * i;
permutation:= fn/(fn_k);
writeln(n,' Permutation ',k,' = ',Permutation:0:0);
end.
 




and the output is like this :





1 comment:

Student Loan Consolidation said...

Your Blog is Fabulous. Good article rather. Very interesting.