**Introduction**

LCM stands for Least Common Multiple. It is the smallest number that is divisible by both numbers.

It is represented by LCM(a, b) or lcm(a, b) where a and b are the two numbers of which we need to find the LCM.

Example:

LCM(4, 8) = 8

LCM(3, 5) = 15

LCM(20, 48) = 240

Also Read, __Binary to Hex Converter____,____C Static Function____,__ ** ****Also Read - **Strong number in c

**Approach 1**

We will follow the following steps to find the LCM of two numbers (A and B):

- We will make a max_div variable and store the maximum of A and B in it.
- We will run a while loop until we find the LCM.
- We will check if max_div is the LCM of A and B. If it is divisible by both then we will break and display max_div, else we will increment max_div.

Refer to the below implementation of the above approach.

```
#include <stdio.h>
void main()
{
int num1 = 18, num2 = 12, max_div, flag = 1;
// max_div variable holds the max divisible number between num1 and num2.
max_div = (num1 > num2) ? num1 : num2;
while (flag) // (flag = 1)
{
if (max_div % num1 == 0 && max_div % num2 == 0)
{
printf( " The LCM of %d and %d is %d. ", num1, num2, max_div);
break;
}
++max_div; // pre-increment max_div
}
}
```

**Output:**

`The LCM of 18 and 12 is 36. `

**Time Complexity:** The time complexity of the above approach is O(A * B) (where A and B are the two numbers). It is because in the worst case, the while loop will run for A * B times.

**Space Complexity:** The space complexity of the above approach is O(1) because we are not using any auxiliary space.

You can also read about __dynamic array in c____, __and __Tribonacci Series__