其他分享
首页 > 其他分享> > JS之百钱买百鸡

JS之百钱买百鸡

作者:互联网

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>百钱买百鸡</title>
    <script>
      function buy(){
        var strs = new Array;
        var x = 0,y = 0, z = 0;
        for(x = 0;x<=20;x++){
          for(y=0;y<34;y++){
            for(z = 0;z<=100;z++){
              var money = x*5 + y*3 + z/3;
              var num = x+y+z;
              if(money==100&&num==100){
                strs.push("公鸡:"+x+",母鸡:"+y+",小鸡:"+z+"\n");
              }
            }
          }
        }
        alert(strs);
      }
    </script>
  </head>
  <body>
    <!-- 公鸡5文钱一只,母鸡3文钱一只,小鸡1文钱3只,如何用100文钱买到100只鸡? -->
    <h1>1."百钱买百鸡"问题</h1>
    <button onclick="buy()">百钱买百鸡</button>
  </body>
</html>
百钱买百鸡

1."百钱买百鸡"问题

百钱买百鸡

标签:function,buy,买百鸡,百钱,JS,var,之百钱
来源: https://blog.csdn.net/weixin_45457317/article/details/119187461