lcm of two numbers

The least common multiple (LCM) of two numbers can be found using the formula:

LCM = (num1 * num2) / GCD

Where num1 and num2 are the two numbers for which we want to find the LCM, and GCD is the greatest common divisor of those numbers.

To find the GCD, we can use the Euclidean algorithm, which involves repeatedly dividing the larger number by the smaller number and taking the remainder as the new smaller number, until the remainder becomes zero.

Here's an example code in C that calculates the LCM of two numbers:

#include <stdio.h>

int gcd(int num1, int num2) {
    if (num2 == 0) {
        return num1;
    }
    return gcd(num2, num1 % num2);
}

int lcm(int num1, int num2) {
    return (num1 * num2) / gcd(num1, num2);
}

int main() {
    int num1, num2, result;

    printf("Enter two numbers: ");
    scanf("%d %d", &num1, &num2);

    result = lcm(num1, num2);

    printf("The LCM of %d and %d is %d\n", num1, num2, result);

    return 0;
}

This code prompts the user to enter two numbers, calculates their LCM using the lcm function, and then displays the result.