Bài học
Lưu code
Refresh
Xoay
Xem kết quả
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>LCM of two numbers</title> <script> function lcm_two_numbers(x, y) { if ((typeof x !== 'number') || (typeof y !== 'number')) return false; return (!x || !y) ? 0 : Math.abs((x * y) / gcd_two_numbers(x, y)); } function gcd_two_numbers(x, y) { x = Math.abs(x); y = Math.abs(y); while(y) { var t = y; y = x % y; x = t; } return x; } docuement.write(lcm_two_numbers(3,15)+"<br/>"); docuement.write(lcm_two_numbers(10,15)+"<br/>"); </script> </head> <body> </body> </html>