Technical Interview

Tips, questions, answers and puzzles at
www.technical-interview.com

Thursday, April 29, 2010

Euclidean algorithm

Write an algorithm for finding the greatest common divisor of two integers.

Ans
function gcd( a,b : Integer ) returns Integer
{
if ( b != 0 )
return gcd( b, a mod b )
return abs(a)
}

No comments:

Post a Comment