Computer Science, asked by AyanChattopadhyay, 1 year ago

Write a program to input two integers and find their Highest Common Factor(H.C.F).
For Example,
INPUT:
Enter 2 integers:
12
8
OUTPUT:
H.C.F. = 4


Write this program in JavaScript (bluej)​

Answers

Answered by iamemma112358
8

PROGRAM CODE

import java.util.*

class demo

{public static void main(String args[])

{Scanner sc=new Scanner(System.in);

int i, n1, n2, min=0, hcf=0; System.out.println("Enter two numbers:");

n1=sc.nextInt();

n2=sc.nextInt();

min=Math.min(n1,n2);

for(i=1;i<min;i++)

{ if(n1%i==0 && n2%i==0)

hcf=i;}

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

}

}

VARIABLE DESCRIPTION

  • i- It is usef for iteration.
  • n1 & n2 - They are used to store the numbers as entered by the user.
  • min- it is used to find the minimum number between n1 and n2.
  • hcf- It is used to dind the value of hcf.

Similar questions