Connor Black Connor Black - 5 months ago 37
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?


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;