Q:

C++ program to find LCM of two numbers using functions

belongs to collection: C++ Basic Solved Programs

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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 .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Basic Solved Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a C++ program to find Square Root of a Numbe... >>
<< C++ Program to Calculate HCF of Two Numbers using ...