Find LCM and HCF of Two Numbers
Here you will learn to find LCM and HCF of two numbers in C++ programming.
Program Code to Find LCM and HCF of Two Numbers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27  | #include <iostream> using namespace std; //HCF Function int hcf(int num1, int num2) {     if (num2 != 0)         return hcf(num2, num1 % num2);     else         return num1; } //LCM Function int lcm(int num1, int num2) {     return (num1 * num2) / hcf(num1, num2); } int main() {     int num1, num2;     cout << "\nEnter two Numbers : ";     cin >> num1 >> num2;     cout << "HCF of " << num1 << " & " <<  num2 << " is : " << hcf(num1, num2);     cout << "\nLCM of " << num1 << " & " <<  num2 << " is : " << lcm(num1, num2);     return 0; }  | 
Output
Enter two Numbers : 8
4
HCF of 8 & 4 is : 4
LCM of 8 & 4 is : 8
Check out our other C++ programming Examples