Computer Science, asked by maheshk07868, 6 months ago

Solved Problers
Problem 1 :
Create a function void PrintHCF( int x, int y)- to find and print HCF/GCD of x and y using Euclid's method for
remainder method). Also, write a main function to input the two integers and print their HCF.
1. Decide the greater from two numbers.
2. Divide the greater number by smaller number, if remainder is zero, print divisor (smaller number) as
HCF otherwise
3. Take divisor as number and remainder as divisor, and repeat steps 2 and 3.​

Answers

Answered by Lokesh1429
5

Answer:

Explanation:

import java.util.*;

class method_HCF

{

   int min,max;

    void PrintHCF(int f,int s)

   {

        max=Math.max(f,s);

        min=Math.min(f,s);

       while(max%min!=0)

       {

           int r=max%min;

           max=min;

           min=r;

       }

       System.out.println("H.C.F="+min);

   }

    static void main()

   {

       Scanner sc=new Scanner(System.in);

       System.out.print("Enter the first number=");

       int a=sc.nextInt();

       System.out.print("Enter the second number=");

       int b=sc.nextInt();

       method_HCF ob=new method_HCF();

       ob.PrintHCF(a,b);

       

   }

}

Similar questions