GCD logic

Generally gcd means greatest common divisor,it means for two numbers there is a greatest and common divisor which is considered as gcd value.

so,as we know that the common divisors exist upto the smaller number only,example

common divisors of 15 and 3

15 - 1,3,5,15

5 - 1,5 common divisors ranges from 1 to the minimum of

the both numbers for any pair of numbers


class Main{
    public static void GCD(int a ,int b)
{
    int A=a;
    int B=b;
    int gcd=1;
    for(int i=1;i<=Math.min(a,b);i++)
    {
        if((A%i==0)&&(B%i==0)){
            gcd=i;
        }

    }
    System.out.println("gcd is "+gcd);
}
public static void main(String args[])
{
 GCD(15,5);
}
}

[Success] Your code was executed successfully

gcd is 5