Write a C++ program to find LCM of two numbers using functions. Here’s simple program to find LCM of two numbers using functions in C++ Programming Language.
A common multiple is a number that is a multiple of two or more numbers. The common multiples of 3 and 4 are 0, 12, 24, ….
The least common multiple (LCM) of two numbers is the smallest number (not zero) that is a multiple of both.
Here is source code of the C++ program to find LCM of two numbers using functions. The C++ program is successfully compiled and run(on Codeblocks) on a Windows system. The program output is also shown in below.
SOURCE CODE : :
/* C++ program to find LCM of two numbers using functions */
#include<iostream>
using namespace std;
void lcm(int,int);
int main()
{
int a,b;
cout<<"Enter 1st number :: ";
cin>>a;
cout<<"\nEnter 2nd number :: ";
cin>>b;
lcm(a,b);
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<<"\n";
}
Output : :
/* C++ program to find LCM of two numbers using functions */
Enter 1st number :: 2
Enter 2nd number :: 15
L.C.M of [ 2 ] and [ 15 ] is :: 30
Process returned 0
Above is the source code for C++ program to find LCM of two numbers using functions which is successfully compiled and run on Windows System.The Output of the program is shown above .
A common multiple is a number that is a multiple of two or more numbers. The common multiples of 3 and 4 are 0, 12, 24, ….
The least common multiple (LCM) of two numbers is the smallest number (not zero) that is a multiple of both.
Here is source code of the C++ program to find LCM of two numbers using functions. The C++ program is successfully compiled and run(on Codeblocks) on a Windows system. The program output is also shown in below.
SOURCE CODE : :
Output : :
Above is the source code for C++ program to find LCM of two numbers using functions which is successfully compiled and run on Windows System.The Output of the program is shown above .
need an explanation for this answer? contact us directly to get an explanation for this answer