LCM(Least Common Multiple)
The Least Common Multiple (LCM) of two or more numbers is the smallest number that is exactly divisible by all the given numbers.
Example:
Find LCM of 4 and 6:
Multiples of 4 → 4, 8, 12, 16, 20...
Multiples of 6 → 6, 12, 18, 24...
--> The smallest common multiple is 12
--> So, LCM(4, 6) = 12
Flowchart
Java
public class Lcm {
public static void main(String[] args) {
int no1=3;
int no2=10;
int big=(no1<no2)?no1:no2;
int big2=big;
while(true) {
if(big%no1==0 && big%no2==0) {
System.out.println("LCM is " + big);
break;
}
big+=big2;
}
}
}
Python
no1=3
no2=10
big=no1 if no1>no2 else no2
big2=big
while True:
if big%no1==0 and big%no2==0:
print("LCM is " , big)
break
big+=big2
javascript
let no1=3;
let no2=10;
let big=(no1<no2)?no1:no2;
let big2=big;
while(true) {
if(big%no1==0 && big%no2==0) {
console.log("LCM is " + big);
break;
}
big+=big2;
}
output
Sum of Numbers
The sum of numbers means the result obtained when two or more numbers are added together.
Example:
2 + 3 = 5 → Here, 5 is the sum
10 + 20 + 30 = 60 → Here, 60 is the sum
Flowchart
java
public class Sum {
public static void main(String[] args) {
int sum=0;
int no=1;
while(no<=10) {
sum=sum+no;
no++;
}
System.out.println("Sum is " + sum);
}
}
python
sum=0
no=1
while no<=10:
sum=sum+no
no+=1
print("Sum is " , sum)
javascript
let sum=0;
let no=1;
while(no<=10) {
sum=sum+no;
no++;
}
console.log("Sum is " + sum);
output
Factorial
The factorial of a number is the product of all positive integers from 1 up to that number.
Example:
5! = 5 × 4 × 3 × 2 × 1 = 120
4! = 4 × 3 × 2 × 1 = 24
Flowchart
Java
public class Factorial {
public static void main(String[] args) {
int fact=1;
int no=1;
while(no<=10) {
fact=fact*no;
no++;
}
System.out.println("Factorial is " + fact);
}
}
python
fact=1;
no=1;
while no<=10):
fact=fact*no
no+=1
print("Factorial is " , fact)
javascript
let fact=1;
let no=1;
while(no<=10) {
fact=fact*no;
no++;
}
console.log("Factorial is " + fact);
output






Top comments (0)