Bluej-
Write a program to evaluate H.C.F of two positive integers in Java
How do people get 10000s of thanks
For like 10 answer huh
I only have 400 something for 100 answers
:l
Tell me the trick too
Answers
Answered by
1
Answer:
=>
public class GCD {
public static void main(String[] args) {
int n1 = 81, n2 = 153;
while(n1 != n2)
{
if(n1 > n2) n1 = n2; else n2 = n1;
Hope it will help u
}
System.out.println("G.C.D = " + n1);
}
}
_______________________________⛄
Answered by
1
Explanation:
Then, a for loop is executed until i is less than both n1 and n2. This way, all numbers between 1 and smallest of the two numbers are iterated to find the GCD.
If both n1 and n2 are divisble by i, gcd is set to the number. This goes on until it finds the largest number (GCD) which divides both n1 and n2 without remainder.
Similar questions