Cognizant Coding Question- 6

One comment on “Cognizant Coding Question- 6”


  • Aqib

    You can Try this Way :
    import java.util.*;
    public class GCD {
    public static void main(String args[])
    {
    int a,b;
    Scanner sc=new Scanner(System.in);
    a=sc.nextInt();
    b=sc.nextInt();
    int n=Math.min(a, b);
    for(int i=n;i>=1;i–)
    {
    if(a%i==0&&b%i==0)
    {
    System.out.println(i);
    break;
    }
    }

    }

    }