Program #7 Finding LCM of a given two numbers in java

preview_player
Показать описание
This program demonstrates how to find LCM of given two numbers in java
Рекомендации по теме
Комментарии
Автор

Excuse me sir, , ,
Here inside the for loop parenthesis 'i' should only be smaller than or equals to a or it should also be smaller than or equals to b??
BTW, , it is really helpful sir, , thank u

aradhyarai
Автор

this logic is not working . if b is greater than a.

rajatdubey
Автор

WHY WE NEED TO USE OF DUMMY VARIABLE g=0;

shortsboi
Автор

Scanner scan = new Scanner(System.in);
System.out.println("Enter the number 1");
int a= scan.nextInt();

System.out.println("Enter the number 2");
int b = scan.nextInt();

int g = 0;

for (int i = 1; i <= a; i++){

if (a%i==0 && b%i==0){

g=i;

}
int lcm = a*b/g;
System.out.println(lcm);

}

}
}

ckal