Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
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

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
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 3 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: