C++ LCM Calculator code

 I made this when doing a maths assignment. Enjoy:

#include <iostream>

using namespace std;

int main()

 {  

    int n1, n2, hcf, temp, lcm;

    cout << "Enter two number" ;                cin >> n1 >> n2;

    hcf = n1; 

    temp = n2; 

    while(hcf != temp)    

     {       

         if(hcf > temp)

         {             

          hcf -= temp;

         }

          else 

          {

                      temp -= hcf;   

           }

     }

    lcm = (n1 * n2) / hcf;

    

    

    cout << "LCM = " << lcm;                    return 0;

 }

Comments