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

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 "how to find the greatest common divisor of 2 numbers in c++"

Browse Popular Code Answers by Language