Please login

Prime

Prepinsta Prime

Video courses for company/skill based Preparation

(Check all courses)
Get Prime Video
Prime

Prepinsta Prime

Purchase mock tests for company/skill building

(Check all mocks)
Get Prime mock

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;
    }
    }

    }

    }