Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
LCD,GCM
Author Message
yuethomas

Posted: Tue Apr 01, 2003 7:18 pm   Post subject: (No subject)

 code: ...     c := getPositiveInteger ...

This line prompts you to enter another number for C. As I am not familiar with the algorithm for calculating the GCM of two numbers, I have no idea what it's for.

Update:

After analyzing the algorithm, I think it's perfectly safe to change
 code: var greatest, t, a, b, c : int     c := getPositiveInteger     a := c

into
 code: var t, a, b : int     a := m

MysticAngel

Posted: Wed Apr 02, 2003 6:06 pm   Post subject: (No subject)

i dont know why this isnt working ????
 code: 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 count, count1 : int     loop         count := count + 1         count1 := count1 * count         exit when count = n         end loop     result count1 end Factorial %----------------------------------------- function Permutation (n, r : int) : real        var p : int     p := Factorial(n) div (n - r)     result p end Permutation %---------------------------------------- function Combination (n, r : int) : real     var c : int     c := Factorial(n)  div r*(n-r)     result c end Combination %------------------*Main Program------------------------- var num1, num2, a, b : int 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 a     b :=Combination (num1,num2)     put b end if
Tony

Posted: Wed Apr 02, 2003 6:19 pm   Post subject: (No subject)

thats because your functions return real values, but you try to assign them to integer varaibles.

declear a,b as real and it should work
Tony's programming blog. DWITE - a programming contest.
MysticAngel

Posted: Wed Apr 02, 2003 8:20 pm   Post subject: (No subject)

is this correct. like this is n!. if u input 5 the answer shuld be (5! = 1*2*3*4*5) = 120

[/code]
function Factorial(n: int): real
var count,e : int
count := 1
loop
count := count + 1
e := 1 * count
exit when count = n
end loop
result n
end Factorial
Prince

Posted: Wed Apr 02, 2003 8:35 pm   Post subject: (No subject)

try splitting the factorial function so ur finding the factorial of num1, num2 and num1 - num2... finding the permutations and combinations should b easier then
MysticAngel

Posted: Wed Apr 02, 2003 8:43 pm   Post subject: (No subject)

huh ?????
MysticAngel

Posted: Wed Apr 02, 2003 9:20 pm   Post subject: (No subject)

I dont understand what u said. how do i do that
Prince

Posted: Wed Apr 02, 2003 9:24 pm   Post subject: (No subject)

like this

 code: function nFactorial (n : int) : real     var N : real := 1     for j : 1 .. n         N := N * j     end for     result N end nFactorial

thats for num1

 code: function rFactorial (r : int) : real     var R : real := 1     for j : 1 .. r         R := R * j     end for     result R end rFactorial

thats num2

 code: function nrFactorial (var n, r : int) : real     var NR : real := 1     for j : 1 .. n - r         NR := NR * j     end for     result NR end nrFactorial

and that one is num1 - num2... it may seem confusing (ok it really is) but its really not that hard (especially since i did this last year )

MOD Edit: thx for the help +10Bits - Tony

MysticAngel

Posted: Wed Apr 02, 2003 9:30 pm   Post subject: (No subject)

So when i call it somewhere i would call nrFactorial rite?
Prince

Posted: Wed Apr 02, 2003 9:45 pm   Post subject: (No subject)

thats rite
yuethomas

Posted: Wed Apr 02, 2003 9:56 pm   Post subject: (No subject)

Uh, a factorial can only result in an integer. No sense declaring it as a REAL function.
Prince

Posted: Wed Apr 02, 2003 10:14 pm   Post subject: (No subject)

test any one of those functions with a value over 10 and u'll see y it has to b REAL... did u do it?? ok then...
Tony

Posted: Wed Apr 02, 2003 10:43 pm   Post subject: (No subject)

damn low level turing C++'s int variable is much larger is size
Tony's programming blog. DWITE - a programming contest.
MysticAngel

Posted: Sat Apr 05, 2003 5:57 pm   Post subject: (No subject)

in a number theory, wat does the sum of the proper factors of a number mean. i mean how would you frame it.
yuethomas

Posted: Sun Apr 06, 2003 1:04 am   Post subject: (No subject)

Proper factors of a number is the factors of that number except 1 and the number itself. For example, the proper factors of 30 are 2, 3, 5, 6, 10, and 15.

So the sum of the proper factors of 30 would be 2+3+5+6+10+15=31.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 2 of 4  [ 51 Posts ]
Goto page Previous  1, 2, 3, 4  Next
 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: