Q:

C++ Program To Find GCD Using Functions

0

Write A C++ Program To Find GCD (Greatest Common Divisor ) Using Functions

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include<iostream>
//#include<cstdlib>

using namespace std;

int gcd(int n,int m);

int main()
{
    int n,m,result;
    cout<<"\nEnter The Two Number To Find The GCD :\n";
    cin>>n>>m;
 
    result=gcd(n,m);
    cout<<"\nGCD of "<<n<<" and "<<m<<" is "<<result<<endl<<endl;

    return 0;
}
int gcd(int n,int m)
{
    if((n>=m)&&((n%m)==0))
        return(m);
    else
        gcd(m,(n%m));
}

 

Output:

Enter The Two Number To Find The GCD :

36

24

GCD of 36 and 24 is 12

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Swapping of Two Numbers in C++ Using Functions | C... >>
<< C++ Program To perform All Arithmetic Operations U...