728x90 AdSpace

Latest Article

Recursive Function Example in C++ Code GCD





How to use Recursive Function Example in C++ programming Code of GCD calculating

1. What will be the output of this code?

int GCD (int A, int B)
{
   cout << "A : " <<A << " B : " <<B << endl;


    if (A > B)
    {
        A = A - B;
        return GCD (A, B);
    }
    else if (A < B)
    { 
        B = B - A;
        return GCD (A, B)
    }

    else if (A = B)
    {
        return A;
    }
}

int main()
{
    int A = 45, B = 55;

    cout << "The GCD is " << GCD(A,B) << endl;
     system("pause");
    return 0;
}



A : 45 B :55
A : 45 B :10
A : 35 B :10
A : 25 B :10
A : 15 B :10
A : 5 B :10
A : 5 B :5
The GCD is 5

 
 






 

no image





  • Blogger Comments
  • Facebook Comments

0 comments:

Post a Comment

Top