top of page
shishantpandey

HOW TO FIND HCF LCM IN JAVASCRIPT




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; } }




5 views0 comments

Recent Posts

See All

Comments


Post: Blog2_Post
bottom of page