Find LCM of two numbers in C++

Google Advertisements

GCD of Two Number in C++ Squre Root Program in C++

C++ program to find LCM of two numbers

To find the LCM (Least Common Multiple) of two or more numbers, make multiple of numbers and choose common multiple. Then take lowest common multiple, this lowest common multiple is LCM of numbers. For example;

LCM

Suppose find LCM of 3 and 4
Multiple of 3 : 3, 6, 9, 12, 15, 18, 21, 24,.......
Multiple of 4 : 4, 8, 12, 16, 20, 24, 28,.....

So, common multiple of 3 and 4 is 12, 24
and Least Common Multiple is 12
LCM of 3 and 4 is: 12

C++ program to find LCM of two numbers

#include<iostream.h>
#include<conio.h>

void lcm(int,int);

void main()
{
    int a,b;
    clrscr();
    cout<<"Enter two numbers: ";
    cin>>a;
    cin>>b;
    lcm(a,b);
    getch();
  //  return 0;
}

//function to calculate l.c.m
void lcm(int a,int b)
{
    int m,n;

    m=a;
    n=b;

    while(m!=n)
    {
	if(m < n)
	{
	m=m+a;
	}
	else
	{
	    n=n+b;
	    }
    }

    cout<<"\nL.C.M of "<<a<<" and "<<b<<" is "<<m;
}

Example

Enter any two number: 
3
15
L.C.M of 3 & 15 is 3

GCD of Two Number in C++ Squre Root Program in C++

Google Advertisements

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: [email protected] or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

Download Projects

Media.net Advertisements


Buy Websites 9999595223

Buy Fresh and Payment Receive Media.net Account with Website. Contact on: [email protected] or 9999595223 Try this Keyword C++ Programs