The question is as follow:
Write a code to get 2 integers as input and find the HCF of the 2 integer without using recursion or Euclidean algorithm.
Input Description:
A single line containing 2 integers separated by space.
Output Description:
Print the HCF of the integers.
Sample Input :
2 3
Sample Output :
1
My answer is as follow:
var a = userInput[0].split(" ").map(Number);
var min;
var hcf = 1;
if(a[0]<a[1]){
min = a[0];
}
else{min = a[1];}
for(var i = 1; i<=min; i++){
if(a[0]%i===0 && a[1]===0){
hcf = i;
}
}
console.log(hcf);
I am not getting what's wrong in my code, Kindly help.