0
1.6kviews
Write a recursive and non-recursive function to calculate the GCD of two numbers.

Mumbai University > COMPS > Sem 3 > Data Structures

Marks: 5 M

Year: Dec 2014

1 Answer
0
3views
  • Here is the recursive function to calculate the GCD of two numbers a and b:-

    intgcd(int a, int b){
    while(a != b)
            if(a > b) return gcd(a-b, b);
            else return gcd(a, b-a)
        return a;
    }
    
  • Here is the non-recursive version:-

    int gcd(int a, int b){
        while(a != b)
            if (a …

Create a free account to keep reading this post.

and 5 others joined a min ago.

Please log in to add an answer.