<!DOCTYPE html>
<html leng = 'en'>
<head>
<meta charset = 'UTF-8'/>
</head>
<body>
<script>
var num1 = parseInt(prompt('请输入相比较的两个数中较大一位'));
var num2 = parseInt(prompt('请输入相比较的两个数中较小一位'));
function test(num1, num2){
var rem = num1 % num2;
if(rem === 0){
return console.log('公约数是' + num2);
}
num1 = num2;
num2 = rem;
return test(num1, num2);
}
test(num1, num2);
</script>
</body>
</html
js write the greatest common divisor of two numbers (Euclidean algorithm)
Guess you like
Origin blog.csdn.net/weixin_48727085/article/details/107705026
Ranking