GCD of two numbers

class Q1iPage139{
    static int a=20,b=30;
    public static void main(String ar[]){
        int x=test(6,18);
        System.out.println(x);
    }
    static int test(int a,int b){
        int gcd=0;
        int c=(a<b)?a:b;
        for(int i=1;i<=c;i++){
                if((a%i==0)&&(b%i==0)){
                    gcd=i;
                }
        }
        return gcd;
    }
}

No comments:

Popular Posts