C program to find LCM of two Numbers

# C program to find LCM of two Numbers

2110
5
SHARE

C program to Find of two Numbers : LCM i.e. Least Common Multiple also called the lowest common multiple or smallest common multiple of two integers a and b, is the smallest positive integer that is a multiple of both a and b or we can simply define LCM of two as the least number(c) that is divisible by both the two numbers(a and b).

Consider an example:
We need to find the LCM of two numbers 8 and 6?
Now we need to find the least common multiple which will be a multiple of both. For achieving this we need to look for the multiple’s of both.
Multiples of 8 are 8,16,24,32,40,48,56,64,72,80 and so on..
Multiples of 6 are 6,12,18,24,30,36,42,48,54,60 and so on…
So we can easily see 24 is the least multiple which lies in the multiple of both 8 and 6. Hence 24 is the LCM of 8 and 6.

I have written a simple C program to find LCM of two numbers using modular method or simply say remainder concept. That may not be the optimized approach but the easiest one to calculate LCM of two numbers.

## C program to find LCM of two Numbers :

```#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,n;
printf("\nEnter two numbers: ");
scanf("%d%d",&a,&b);
for(n=1;;n++)
{
if(n%a==0 && n%b==0)
{
printf("\nLCM of %d and %d is : %d",a,b,n);
getch();
return 0;
}
}
}```

There can be several ways of coding this but i can guarantee that this is the easiest and smallest way :P. Have fun! If you have any issues with code or logic ask me in form of comments.

SHARE
Previous articleC program to find Inverse of Matrix
Next articleC program to find GCD of two Numbers
Well, I am software programmer and love to code. My hobbies is to do Hacking, Coding, Blogging, Web Designing and playing online games. Feel free to contact me at shiviskingg@gmail.com or lokesh@hackingloops.com