Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 LowestCommonMultiple
Index -> Programming, C++ -> C++ Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
[Gandalf]




PostPosted: Sat Nov 12, 2005 4:04 pm   Post subject: (No subject)

So now you don't have to type syntax = c++ before your code, just do it inside the tags. You also don't have to double post because you can edit your posts. Even better, if you wanted to check if it works you could have used the preview button and edited your post before posting it Smile.
Sponsor
Sponsor
Sponsor
sponsor
Geminias




PostPosted: Sun Nov 13, 2005 7:53 pm   Post subject: (No subject)

lol, ya ya, i'm a big noob. laugh while you still can Razz
wtd




PostPosted: Sun Nov 13, 2005 8:06 pm   Post subject: (No subject)

We're all noobs next to someone.
md




PostPosted: Sun Nov 13, 2005 10:09 pm   Post subject: (No subject)

I disagree! I'm a noob next to everyone! Wait...

In any case it's alright to make mistakes, so long as you learn from them Smile
Flikerator




PostPosted: Tue Nov 15, 2005 3:01 pm   Post subject: (No subject)

Cornflake wrote:
I disagree! I'm a noob next to everyone! Wait...

In any case it's alright to make mistakes, so long as you learn from them Smile


Except when sky diving...Its better to learn from other peoples mistakes Rolling Eyes Wink
bugzpodder




PostPosted: Tue Nov 15, 2005 6:13 pm   Post subject: Re: LowestCommonMultiple

Viper wrote:
**Recursion must be used**
The LCM (lowest common multiple ) of two non-zero integers can be found using the formula: lcm(num1, num2) = num1*num2/ gcd(num1, num2) where: gcd(num1, num2) is the greatest common divisor of num1 and num2. here's the trick. the program should employ a recursive approach to finding the gcd of two number. The recursive definition is given by:
if num2 divides evenly into num1 then
gcd= num2

could someone re-write tht in C++ for me plz Very Happy

here it is in turing
code:
var lcm, gcd : real := 0
var num1, num2 : int := 0
%------------------------------------------------------------------------------------------
proc starter
    put "Enter the numbers you wish to find the 'LCM' for"
    put "***********Hit enter after each number**********"
    get num1
    get num2
end starter
%------------------------------------------------------------------------------------------
proc GCD (num1, num2 : real)
    if num1 mod num2 = 0 then
        gcd := num2
    else
        GCD (num2, num1 mod num2)
    end if
end GCD
%------------------------------------------------------------------------------------------
proc LCM (gcd, num1, num2 : real)
    lcm := num1 * num2 / gcd
    put "The 'LCM' for", " ", num1, " ", "&", " ", num2, " ", "is", " ", lcm
    put "The 'GCD' for", " ", num1, " ", "&", " ", num2, " ", "is", " ", gcd
end LCM

%MAIN-----------------------------------
starter
GCD (num1, num2)
LCM (gcd, num1, num2)


gcd on reals? intriguing!! and I wouldnt do mod 0 if I were you. and be extra careful with negatives
MysticVegeta




PostPosted: Thu Jan 19, 2006 12:25 pm   Post subject: (No subject)

Wow the recursive solution to the GCD and LCM using GCD is amazing.. Never thought about it really.. really neat website wtd, saving a shortcut in my programming folder.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 22 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: