- C program to test if a number is a power of 2
- C program to multiply two number without using multiplication(*) operator
- C program to display Fibonacci series
- C program to compare two numbers without using relational operators
- C program to convert roman number into decimal number
- C program to encrypt and decrypt the string
- C program to make calculator using switch case
- C program to convert temperature from degree celsius to fahrenheit
- Selection sort in C programming
- Binary search in C programming
- C program to sort array using bubble sort algorithm
- Linear Search in C Programming – Program and Explanation
- C program to swap two numbers
- C program to find LCM of two numbers
- C program to find GCD of two numbers
- C program to find LCM and GCD using recursion
- C program to display prime numbers between two numbers using function and without using function
- C program to check whether a string is palindrome or not
- C program to read a character from keyboard and print it in reverse case i.e if input is lower case output will be upper case and vice versa
- C program to check whether a number is prime or not
- C program to check whether a number is positive, negative or zero
- C program to check whether a number is palindrome or not
- C program to check leap year
- C program to check Armstrong number
- C program to calculate the area of square with and without using function
- C program to calculate mean using arrays
- C program to calculate area of circle

In this example, you will learn two ways of calculating LCM (Lowest Common Multiple) of two integers entered by the user (**C program to find LCM of two numbers**).

**LCM **: Lowest Common Multiple of two or more integers is the smallest positive integer that is perfectly divisible by the given integers, without remainder.

For example: LCM of 10 and 20 is 20.

```
#include <stdio.h>
int main()
{
int num1, num2, maxValue;
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
//largest integer among num1 and num2 is stored in maxValue
maxValue = (num1 > num2) ? num1 : num2;
while(1) //always true
{
if ((maxValue % num1 == 0) && (maxValue % num2 == 0))
{
printf("LCM: %d", maxValue);
break;
}
++maxValue;
}
return 0;
}
```

Output

We can also calculate LCM using GCD.

Formula

LCM = (num1 * num2) / GCD

[adsense1]

The above formula can be used to calculate LCM.

```
#include <stdio.h>
int main()
{
int num1, num2, i, gcd, lcm;
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
//calculation of gcd
for(i=1; i <= num1 && i <= num2; ++i)
{
if(num1 % i == 0 && num2 % i == 0)
gcd = i;
}
//calculation of lcm using gcd
lcm = (num1 * num2) / gcd;
printf("LCM: %d", lcm);
return 0;
}
```

Output