Q:

C program to find the LCM (Lowest Common Multiple) of two integers

0

C program to find the LCM (Lowest Common Multiple) of two integers

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Read two integer numbers, and find the (LCM) Lowest Common Multiple of given numbers.

Program:

The source code to find the LCM (Lowest Common Multiple) of two integers is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.

// C program to find the LCM
// (Lowest Common Multiple) of two integers

#include <stdio.h>

int main()
{
    int num1 = 0;
    int num2 = 0;
    int rem = 0;
    int lcm = 0;
    int X = 0;
    int Y = 0;

    printf("Enter Number1: ");
    scanf("%d", &num1);

    printf("Enter Number2: ");
    scanf("%d", &num2);

    if (num1 > num2) {
        X = num1;
        Y = num2;
    }
    else {
        X = num2;
        Y = num1;
    }

    rem = X % Y;

    while (rem != 0) {
        X = Y;
        Y = rem;
        rem = X % Y;
    }

    lcm = num1 * num2 / Y;
    printf("Lowest Common Multiple is: %d\n", lcm);

    return 0;
}

Output:

RUN 1:
Enter Number1: 10
Enter Number2: 20
Lowest Common Multiple is: 20

RUN 2:
Enter Number1: 10
Enter Number2: 225
Lowest Common Multiple is: 450

RUN 3:
Enter Number1: 110
Enter Number2: 17
Lowest Common Multiple is: 1870

Explanation:

Here, we read two integer numbers num1 and num2 from the user and found the Lowest Common Multiple of both numbers, and printed the result on the console screen.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C programming Basic Input, Output, if else, Ternary Operator based Programs

Similar questions


need a help?


find thousands of online teachers now
C program to calculate the area of a triangle give... >>
<< C program to find the GCD (Greatest Common Divisor...