Search code examples
cpseudocode

How to change this pseudocode to C syntax


I've found this pseudocode from Wikipedia of Euclid's extended Algorithm, but I don't know how to return 2 values from a function.

function extended_gcd(a, b)
    if b = 0
        return (1, 0)
    else
        (q, r) := divide (a, b)
        (s, t) := extended_gcd(b, r)
        return (t, s - q * t)

Source: http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm


Solution

  • The template class std::pair could be used for this; i.e.,

    if (b == 0)
        return std::pair<int, int>(1, 0);