DEV Community

S Sarumathi
S Sarumathi

Posted on

Least Common Multiple

1. Least Common Multiple:
Flowchart:

Java Script:
Program:

let no1 = 3;
let no2 = 9;

let big = (no1 > no2) ? no1 : no2;

while (true) {
    if (big % no1 === 0 && big % no2 === 0) {
        console.log(big);
        break;
    }
    big = big + 1;
}
Enter fullscreen mode Exit fullscreen mode

Output:

Java:
Program:

public class Main {
    public static void main(String[] args) {
        int no1 = 3;
        int no2 = 9;

        int big = (no1 > no2) ? no1 : no2;

        while (true) {
            if (big % no1 == 0 && big % no2 == 0) {
                System.out.println(big);
                break;
            }
            big = big + 1;
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Python:
Program:

no1 = 3
no2 = 9

big = no1 if no1 > no2 else no2

while True:
    if big % no1 == 0 and big % no2 == 0:
        print(big)
        break
    big = big + 1
Enter fullscreen mode Exit fullscreen mode

Top comments (0)