小雪拿了100元到超市买东西,毛巾5元一条,牙刷2元一支,牙膏10元一支,刚好花完有多少种购买方式?
<script>
var i = 0;
for (var a = 0; a <= 20; a++) {
for (var b = 0; b <= 50; b++) {
for (var c = 0; c <= 10; c++) {
if (a * 5 + b * 50 + c * 10 == 100) {
i++;
document.write('第' + i + '种方案:毛巾' + a + '条,牙刷' + b + '支,牙膏' + c + '支' + '</br>');
}
}
}
}
document.write("一共有" + i + "种可能性!");
</script>
输出的结果如下:
如果对你有帮助,请点个赞吧!,谢谢~