FOR HCF
let a, b; a = prompt("enter first number"); b = prompt("enter sec number"); a = Number.parseInt(a); b = Number.parseInt(b); max = a > b ? a : b;
min = a < b ? a : b; for (min; min > 1; min--) { if (a % min == 0 && b % min == 0) { document.write("HCF is ", min); break; }
}
FOR LCM
let a, b; a = prompt("enter first number"); b = prompt("enter second number"); a = Number.parseInt(a); b = Number.parseInt(b);
max = a > b ? a : b; for (max; max <= a * b; max++) { document.write(max, "</br>"); if (max % a == 0 && max % b == 0) { document.write("LCM is ", max); break; } }
Comments