Permutations and Combinations
Author |
Message |
MysticAngel
|
Posted: Thu Apr 03, 2003 10:12 pm Post subject: Permutations and Combinations |
|
|
Frankly speaking i dont know what permutations and combinations are myself. but i still did it.
function getPositiveInteger : int
var n : int
loop
get n
exit when n > 0
put "Positive interger please " ..
end loop
result n
end getPositiveInteger
%--------------------------------------------
function Factorial (n : int) : real
var N : real := 1
for j : 1 .. n
N := N * j
end for
result N
end Factorial
%-----------------------------------------
function Permutation (n, r : int) : real
var p : real
p := Factorial(n)/ Factorial(n - r)
result p
end Permutation
%----------------------------------------
function Combination (n, r : int) : real
var c : real
c := Factorial(n) / (Factorial(r)* Factorial(n-r))
result c
end Combination
%------------------*Main Program-------------------------
colorback(91)
cls
color (black)
var num1, num2 : int
var a, b : real
put "Please enter a positive number"
num1 := getPositiveInteger
put "Please enter another positve number"
num2 := getPositiveInteger
if num1 >= num2 then
a := Permutation(num1,num2)
put "Permutation of ", num1 ," & " ,num2, " is " , a : 9 : 0
b := Combination (num1,num2)
put "Combination of ", num1 ," & ", num2, " is ", b : 9:0
end if
i dont understand whats going on myself, but thx for sharing anyway +7Bits - Tony |
|
|
|
|
|
Sponsor Sponsor
|
|
|
yuethomas
|
Posted: Thu Apr 03, 2003 10:50 pm Post subject: (No subject) |
|
|
Combination: "Choosing two fruits out of five, how many ways are there?"
Permutation: "Choosing one fruit then another out of five, how many ways are there?"
Edit: (psst Azndragon, that's what I said.) |
|
|
|
|
|
azndragon
|
Posted: Fri Apr 04, 2003 1:26 pm Post subject: (No subject) |
|
|
Uh, I think it means something else. Combinations and Permutations are similar, but Combinations don't take duplicates.
Example:
1,2,3,4
4,3,2,1
2 Permutations, 1 Combination |
|
|
|
|
|
|
|