Answers for "1) Compute the greatest common divisor of two numbers."

C++
0

how to find the greatest common divisor of 2 numbers in c++

#include<bits/stdc++.h>
using namespace std;
long long UCLN(long long a,long long b)
{
    long long r;
    while (b!=0)
    {
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}


int main()
{
    long long a, b;
    cout<< "enter: ";
    cin>> a;
    cout<< "enter: ";
    cin >>b;
    cout<<UCLN(a,b)<<endl;
    return 0;
}
Posted by: Guest on October-03-2021

Code answers related to "1) Compute the greatest common divisor of two numbers."

Browse Popular Code Answers by Language