import java.io.*;
public class GCD
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a, b, r, q;
System.out.print("\nEnter First Number:: ");
a = Integer.parseInt(br.readLine());
System.out.print("\nEnter Second Number (less than "+a+"):: ");
b = Integer.parseInt(br.readLine());
do
{
r = a % b;
q = a / b;
if (r != 0)
b = r;
} while (r != 0);
System.out.println("\nGCD is:: " + b);
}
}
OUTPUT::
Enter First Number:: 12
Enter Second Number (less than 12):: 8
GCD is:: 4
public class GCD
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a, b, r, q;
System.out.print("\nEnter First Number:: ");
a = Integer.parseInt(br.readLine());
System.out.print("\nEnter Second Number (less than "+a+"):: ");
b = Integer.parseInt(br.readLine());
do
{
r = a % b;
q = a / b;
if (r != 0)
b = r;
} while (r != 0);
System.out.println("\nGCD is:: " + b);
}
}
OUTPUT::
Enter First Number:: 12
Enter Second Number (less than 12):: 8
GCD is:: 4