DEV Community

Divya Divya
Divya Divya

Posted on

Least Common Multiple?

Flow Chart

JavaScript

let no1 =Number( prompt("Enter your Number"))
        let no2 = Number( prompt("Enter your Number"))
        let big = no1 > no2 ? no1 : no2
        let big2 = big
        while (true) {
            if (big % no1 == 0 && big % no2 == 0) {
                console.log("LCM", big);
                break
            }
            big += big2
        }

Enter fullscreen mode Exit fullscreen mode

Output :

Python

no1=int(input("enter 1st number"))
no2=int(input("enter 2ed number"))
big=no1 if no1>no2 else no2
big2=big
while True:
    if big%no1==0 and big%no2==0:
        print(big)
        break
    big+=big2

Enter fullscreen mode Exit fullscreen mode

Output :

Java

public class LCMExample {
    public static void main(String[] args) {

        int no1 = 4;
        int no2 = 6;

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

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

Output:

SUM OF n NUMBERS

Flow Chart

JavaScript

        let sum = 0
        let no = 1
        while (no <= 10) {
            sum = sum + no
            no += 1
        }
        console.log(sum);
Enter fullscreen mode Exit fullscreen mode

Output

Python

sum=0
no=1
while no<=10:
    sum=sum+no
    no+=1
print(sum)
Enter fullscreen mode Exit fullscreen mode

Output :

Java

public static void main(String[] args) {

        int sum=0;
        int no=1;
            while(no<=10){
                    sum=sum+no;
                    no+=1;
            }


        System.out.println("LCM: " + sum);
    }
Enter fullscreen mode Exit fullscreen mode

Output :

FACTORIAL

Python

sum=1
no=1
while no<=5:
    sum=sum*no
    no+=1
print(sum)
Enter fullscreen mode Exit fullscreen mode

Output

Java

public class FactorialExample {
    public static void main(String[] args) {

        int sum = 1;
        int no = 1;

        while (no <= 5) {
            sum = sum * no;
            no++;
        }

        System.out.println(sum);
    }
}


Enter fullscreen mode Exit fullscreen mode

Output

JavaScript


        let sum = 1;
let no = 1;

while (no <= 5) {
    sum = sum * no;
    no++;
}

console.log(sum);
Enter fullscreen mode Exit fullscreen mode

Output

Top comments (1)

Collapse
 
payilagam_135383b867ea296 profile image
Payilagam

Good Attempt!