W a program to find the lcm and gcd of two numbers for beginners
Answers
Answered by
0
hello! here's your answer
LCM :-
import java.util.*;
class LCM
{
public static void main()
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter 2 numbers");
int a = sc.nextInt();
int b = sc.nextInt();
int hcf = 0;
int Lcm = 0;
for(int i = 1 ; i <= a ; i++))
{
if(a%1 == 0 && b%i == 0)
hcf = i;
Lcm = (a*b)/hcf;
}
System.out.println("The LCM = "+ Lcm);
}
}
HCF:-
import java.util.*;
class HCF
{
public static void main()
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter 2 numbers");
int a = sc.nextInt();
int b = sc.nextInt();
int hcf = 0;
for(int i = 1 ; i <= a ; i++))
{
if(a%1 == 0 && b%i == 0)
hcf = i;
}
System.out.println("The HCF = "+ hcf);
}
}
Answered by
0
Answer:
One major difference between greedy algorithms anddynamic programming is that instead of first finding optimal solutions to subproblems and then making an informed choice, greedy algorithms first make a greedy choice, the choice that looks best at the time, and then solve a resulting subproblem, without bothering to ...
Similar questions