zoukankan      html  css  js  c++  java
  • JavaScript计算 a+aa+aaa...... a是数字

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    </head>
    <body>
        <script>
    
            /**
             *  a+aa+aaa+...的和  a是数字
             * @param num 指定循环的数字
             * @param size  循环的次数 例如:2,22=20+2,222=200+22....
             */
    
            function t4(a,count){
                var sum =0, b=0
    
                for(var i=1;i<count;i++){
                    b = b + a
                    sum = sum+b
                    a = a*10
                }
                return sum
            }
    
    
            console.log(t4(2,4))
    
    
        </script>
        
    </body>
    </html>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    </head>
    <body>
        <script>

            /**
             *  a+aa+aaa+...的和  a是数字
             * @param num 指定循环的数字
             * @param size  循环的次数 例如:2,22=20+2,222=200+22....
             */

            function t4(a,count){
                var sum =0, b=0

                for(var i=1;i<count;i++){
                    b = b + a
                    sum = sum+b
                    a = a*10
                }
                return sum
            }


            console.log(t4(2,4))


        </script>
        
    </body>
    </html>
  • 相关阅读:
    SGU 275. To xor or not to xor
    4364: [IOI2014]wall砖墙
    3211: 花神游历各国
    5248: [2018多省省队联测]一双木棋
    3106: [cqoi2013]棋盘游戏
    POJ 1568 Find the Winning Move
    P3527 [POI2011]MET-Meteors
    P2617 Dynamic Rankings
    3262: 陌上花开
    1176: [Balkan2007]Mokia
  • 原文地址:https://www.cnblogs.com/qiuyehaha/p/12935218.html
Copyright © 2011-2022 走看看