<!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>