HCF and LCM using STL(Standard Template Library)
There is an easy way to find HCF(Highest Common Factor) using STL library <algorithm>.
To find HCF, we use :-
__gcd(int a, int b)
The only thing to watch is that the numbers that we give as inputs must be integers.
using namespace std;
int a = 18;
int b = 21;
cout << "HCF = " << __gcd(a, b) << "\n";
// cout << __gcd(18.0, 21) .................This causes error because no typecasting occurs
cout << "LCM = " << (a*b)/__gcd(a, b);
HCF = 3
LCM = 126