Thursday, 17 May 2012

Function to find GCD using Euclidean Algorithm

int GCD(int a, int b)
{
     while (a != 0 && b != 0)
     {
         if (a > b)
            a %= b;
         else
            b %= a;
     }

     if (a == 0)
         return b;
     else
         return a;
}

No comments:

Post a Comment