zoukankan      html  css  js  c++  java
  • 百钱白鸡(for循环的练习)

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    </head>
    
    <body>
    </body>
    </html>
    <script>
        //    百钱百鸡   公鸡2文,母鸡1文,小鸡半文,每种至少一只,100文买100只鸡有多少可能性
    // 写条件gj*2 + mj*1 + xj*0.5 == 100  && gj+mj+xj=100
        var num = 0;
        for(var gj = 1 ; gj <= 50 ; gj++){
            for(var mj = 1 ;mj <= 100 ; mj++){
                for(var xj = 1 ; xj <=200 ;xj++){
                    if(gj*2 + mj*1 + xj*0.5 == 100  && gj+mj+xj ==100){
                        console.log("公鸡"+gj+"只,母鸡"+mj+"只,小鸡"+xj+"");
                        num ++;
                    }
                }
            }
        }
        console.log("总共有"+num+"种可能性");
    </script>
  • 相关阅读:
    数组函数
    跨域
    连接数据库的几种方式
    PHP语言的优缺点
    盗链
    缓存
    电商架构演进
    分布式集群
    序列化
    json
  • 原文地址:https://www.cnblogs.com/lsqbk/p/10259005.html
Copyright © 2011-2022 走看看