Horje
c++ program to find lcm of two numbers Code Example
c++ program to find lcm of two numbers
#include<iostream>
using namespace std;

int main(){
  int num1,num2,temp,lcm,hcf;
  cout<<"Enter 1st number"<<endl;
  cin>>num1;
  cout<<"Enter 2nd number"<<endl;
  cin>>num2;
  if (num1>=num2){
    temp=num1;
    num1=num2;
    num2=temp;
  }
  for (int i=1 ; i<=num1 ; i++){
    if (num1%i==0 && num2%i==0){
      hcf=i;
    }
  }
  // MATHEMATICAL FORMULA : HCF * LCM = NUM1 * NUM2
  lcm = (num1*num2)/hcf;
  cout<<"Least Common Multiple of "<<num1<<" and "<<num2<<" is "<<lcm<<endl;
  return 0;
}




Cpp

Related
adding two dates using necessary member function in c++ Code Example adding two dates using necessary member function in c++ Code Example
semi colon in argument list c++ Code Example semi colon in argument list c++ Code Example
C++ passing function arguments to a thread Code Example C++ passing function arguments to a thread Code Example
how to get characters through their ascii value in c++ Code Example how to get characters through their ascii value in c++ Code Example
c++ error missing terminating character Code Example c++ error missing terminating character Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7