Función C GCD C
ll gcd(ll a, ll b)
{
if (b==0)return a;
return gcd(b, a % b);
}
Ugliest Unicorn
ll gcd(ll a, ll b)
{
if (b==0)return a;
return gcd(b, a % b);
}
// CPP program to illustrate
// undefined behavior of
// gcd function of C++ STL
#include <iostream>
#include <algorithm>
// #include<numeric> for C++17
using namespace std;
int main()
{
cout << "gcd(6, 20) = " << __gcd(2.0, 8) << endl; // gcd(2.0,8) for C++17
}
#include <iostream>
using namespace std;
int main() {
int n1, n2, hcf;
cout << "Enter two numbers: ";
cin >> n1 >> n2;
// swapping variables n1 and n2 if n2 is greater than n1.
if ( n2 > n1) {
int temp = n2;
n2 = n1;
n1 = temp;
}
for (int i = 1; i <= n2; ++i) {
if (n1 % i == 0 && n2 % i ==0) {
hcf = i;
}
}
cout << "HCF = " << hcf;
return 0;
}