- 鸡兔同笼问题
先有兔和鸡装在同一个笼子中,鸡兔同笼35个头94只脚用 鸡有多少只 兔有多少只?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script>
// i:鸡
// j:兔
for (var i = 0; i <=35; i++) {
for (var j = 0; j <=35; j++) {
if(i*2+j*4==94&&i+j==35){
console.log(i,j);
}
}
}
</script>
</body>
</html>
2. 百钱买百鸡
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script>
// a:小鸡 1/3元每只;
// b:公鸡 5元每只;
// c:母鸡 3元每只;
var count = 0;
for (var a = 0; a <= 100; a++) {
for (var b = 0; b <= 20; b++) {
for (var c = 0; c <= 33; c++) {
if (a * 1 / 3 + b * 5 + c * 3 == 100 && a + b + c == 100) {
count++;
document.write(`第${count}种方法:${a},${b},${c}<br>`);
}
}
}
}
document.write("共:" + count + "种方法");
</script>
</body>
</html>