Connor Black Connor Black - 1 year ago 268
C++ Question

GCD function in c++ sans cmath library

I'm writing a mixed numeral class and need a quick and easy 'greatest common divisor' function. Can anyone give me the code or a link to the code?

Answer Source

I'm tempted to vote to close -- it seems difficult to believe that an implementation would be hard to find, but who knows for sure.

unsigned GCD(unsigned u, unsigned v) {
    while ( v != 0) {
        unsigned r = u % v;
        u = v;
        v = r;
    return u;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download