羽毛球拍15元,球3元,水2元。200元每种至少一个,200花完有多少可能
程序员文章站
2022-06-27 20:39:03
var a = 15; var b = 3; var c = 2; var money = 200; var n = 0; for (i = 1; i <= money / a; i++) {//最多买money / a个球拍 for (j = 1; j <=...
var a = 15;
var b = 3;
var c = 2;
var money = 200;
var n = 0;
for (i = 1; i <= money / a; i++) {//最多买money / a个球拍
for (j = 1; j <= money / b; j++) {//最多买money / b个球
for (k = 1; k <= money / c; k++) {//最多买money / c个水
if (i * a + j * b + k*c == 200) {//正好花完200
n++;//每次的可以+1
}
}
}
}
console.log("有"+n+"种可能");