<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<script type="text/javascript">
var KABULIEKE = 495;
var num = parseInt(prompt("请输入一个三位数,三位数不能相同"));
while(num != KABULIEKE){
var max = getMax(num);
var min = getMin(num);
num = max - min;
document.write(max+"-"+min+"="+num+"<br>");
}
function getMax(n){
var b100 = Math.floor(num / 100);
var b10 = Math.floor(num % 100 / 10);
var b1 = Math.floor(num % 10);
var bw = Math.max(b100,b10,b1);
var gw = Math.min(b100,b10,b1);
var sw = (b100 + b10 + b1) - bw - gw;
return bw * 100 + sw * 10 + gw;
}
function getMin(n){
var b100 = Math.floor(num / 100);
var b10 = Math.floor(num % 100 / 10);
var b1 = Math.floor(num % 10);
var bw = Math.min(b100,b10,b1);
var gw = Math.max(b100,b10,b1);
var sw = (b100 + b10 + b1) - bw - gw;
return bw * 100 + sw * 10 + gw;
}
</script>
<body>
</body>
</html>
JavaScript卡布列克常数
最新推荐文章于 2024-09-04 20:18:34 发布