Slideshow

Monday, 25 February 2013


Write a recursive algorithm to find Greatest Common Divisor of two integers
with the help of Euclid’s algorithm, as per the following formula
GCD (m, n mod m) otherwise
m if n m and n mod m 0
GCD(m,n) if n m
GCD(n,m) (4)

Ans:
Recursive algorithm to find the GCD of two numbers using Euclid’s
algorithm is as follows;
int gcd (n, m)
{
if (n < m)
return (gcd (m, n));
else if ( n >= m && n % m == 0)
return (m);
else
return (gcd (m, n % m));

No comments:

Post a Comment