Monday, May 24, 2010

I want c program in c language lcd gcd with recursive function?

To Calculate the GCD of two numbers recursively, you can use


1) Euclid's Algorithm:





int gcd(int m, int n) {


if ((m % n) == 0)


return n;


else


return gcd(n, m % n);


}


OR


2) Dijkstra's Algorithm


int gcd(int m, int n) {


if(m == n)


return m;


else if (m %26gt; n)


return gcd(m-n, n);


else


return gcd(m, n-m);


}


OR


3) BRUTE force guessing


int tryDivisor(int m, int n, int g) {


if (((m % g) == 0) %26amp;%26amp; ((n % g) == 0))


return g;


else


return tryDivisor(m, n, g - 1);


}


In this last one, g is a guess. If the guess works, then it returns the guess. Otherwise, it tries a smaller guess.

I want c program in c language lcd gcd with recursive function?
This might help you with your homework:





http://www.google.co.uk/search?hl=en%26amp;q=l...





Rawlyn.


No comments:

Post a Comment