04-26-2004, 11:39 AM | #2 (permalink) |
Location: Waterloo, Ontario
|
Do you just not know the various algorithms for finding the greatest common divisor or can't you just implement them, yourself? They're pretty simple and shouldn't take you long to do...
|
04-26-2004, 11:48 AM | #3 (permalink) |
Upright
|
I have the technical aspects of the Euclidean, but I'm not sure how to translate the definition from a math textbook into c++ code.
I just thought there might be a pre-written c++ function out there that I could stick into a program and take advantage of. Thanks, Tom |
04-26-2004, 12:26 PM | #5 (permalink) |
Location: Waterloo, Ontario
|
Good for you! There's a small bug in your code (remainder is uninitialized) but, otherwise, it should work... You can either initialize your variables, change your while() loop into a do{}while() loop, or both...
I was about to suggest this: Code:
unsigned int GCD( unsigned int a, unsigned int b) {
 return b == 0 ? a : GCD( b, a % b);
} |
04-26-2004, 01:02 PM | #7 (permalink) |
Wehret Den Anfängen!
Location: Ontario, Canada
|
Knife, actually they don't.
If b>a, his GCD code (and I assume yours) swaps a and b in the first iteration, and goes on from there.
__________________
Last edited by JHVH : 10-29-4004 BC at 09:00 PM. Reason: Time for a rest. |
Tags |
algorithm, euclidean |
|
|