C program to find LCM of two Numbers

C program to find LCM of two Numbers


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 :

int main()
int a,b,n;
printf("\nEnter two numbers: ");
if(n%a==0 && n%b==0)
printf("\nLCM of %d and %d is : %d",a,b,n);
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.


  1. Děkuji za připomednku, topened je skutečně proble9m nelze vyte1pět jen tu jednu medstnost, mused se vytopit cele1 solonovka a to stojed moc peněz. Minule (3.11.) jsem přinesla z domova ještě jedny el. kamna a bylo tam tepledčko po celou dobu, protože topedm už od 6.45 hod. Takže topit budeme samostatně do doby, než začnou mrazy a solonovka bude vyte1pěna cele1. Pan spre1vce nabeddl, že ne1m přinese dalšed kamna (svoje vlastned), abychom tento proble9m vyřešili.

  2. Many thanks so much for this! I¡¯ve not been this moved by a web site publish for quite some time! You might have obtained it, whatever that means in blogging. Anyway, You¡¯re unquestionably someone that has something to say that folks require to hear. Sustain the superb work. Hold on inspiring the individuals!

  3. i feel difficulty to understand this line if(n%a==0 && n%b==0). can u tell me that how it works, and what is the purpose of “&&” sign…..?