Computer Science, asked by ridakhuraishi64, 10 months ago

Write a program to input two numbers and display highest common factor of two numbers using function int hcf(int,int)which returns highest common factor of two numbers.

Answers

Answered by arkohrishi
0

Answer:

import java.util.*;

public class HCF

{public int hcf (int a,int b)

   {int i=1,c=0;

       for (;i<=a && i<=b;i++)

       {if (a%i==0 && b%i==0)

           c=i;

       }

       return c;

   }

   public static void main(String args[])

   {int a,b,c;

       HCF ob=new HCF();

       Scanner sc=new Scanner(System.in);

       System.out.println("Enter 2 numbers");

       a=sc.nextInt();

       b=sc.nextInt();

       c=ob.hcf(a,b);

       System.out.println("HCF = "+c);

   }

}

Explanation:

Attachments:
Similar questions