Find the GCD of two numbers without using divison or mod operator?

algorithm, c, numbers

Solution

You can use the substraction based version of euclidean algorithm up front:

function gcd(a, b)
    if a = 0
       return b
    while b ≠ 0
        if a > b
           a := a − b
        else
           b := b − a
    return a

Problem

I want to find GCD of two numbers but without using division or mod operator. one obvious way would be to write own mod function like this: ``` enter code here int mod(int a, int b) { while(a>b) a-=b; return a; } ``` and then use this function in the euclid algorithm. Any other way ??

Original source