the greatest common divisor of two integers is calculated by the continued division method.Divide the larger number by smaller, the remainder then divides the previous divisor.The process repeats unless the remainder reaches zero. The last divisor results in greater common divisor
Answers
Answer:
The GCD (Greatest Common Divisor) of two numbers is the largest positive integer number that divides both the numbers without leaving any remainder. For example. GCD of 30 and 45 is 15. GCD also known as HCF (Highest Common Factor). In this tutorial we will write couple of different Java programs to find out the GCD of two numbers.
How to find out the GCD on paper?
To find out the GCD of two numbers we multiply the common factors as shown in the following diagram:
Finding GCD of numbers in Java
Explanation:
hope i help you so much
Answer:
import java.util.*;
import java.io.*;
public class Program {
public static void main(String []args) throws IOException{
int num1 = 45, num2 = 20, gcd = 1;
for(int i = 1; i <= num1 && i <= num2; i++)
{
if(num1%i==0 && num2%i==0)
gcd = i;
}
System.out.println("GCD of 45 and 20 is: " + gcd);
}}
Explanation:
GCD of 45 and 20 is: 5