Showing posts with label gcd-of-two-numbers. Show all posts
Showing posts with label gcd-of-two-numbers. Show all posts

Monday, July 6, 2020

Write a program to input two integers and find the GCD/HCF of two numbers (using division method)? (10,12, HCF=2)

41)   Write a program to input two integers and find the GCD/HCF of two numbers (using division method)? (10,12,   HCF=2)

import java.util.*;
public class GCD
{
    public static void main(String args[ ])
   {
      Scanner sc = new Scanner (System.in);
      System.out.println("Enter two numbers");
      int a = sc.nextInt();
      int b = sc.nextInt();
      int k = Math.min(a,b);
      b = Math.max(a,b);
      a=k;
      while(k!=0)
      {
          k=b%k;
          if(k!= 0)
          {
              b=a;
              a=k;
          }
      }
      System.out.println("G.C.D = "+a);
   }
}




 jhvghvgk ;nkjn ,nkjhj