1 <script type="text/javascript"> 2 window.onload = function() { 3 var n =81; 4 // 求组数 5 var zushu = Math.floor(n / 2); 6 var sum = (1 + 81) * (zushu) + (zushu + 1) * (n % 2); 7 console.log("总和为:" + sum); 8 var avg = sum / 3; 9 console.log("平均数为:" + avg); 10 var thisSum = 0;// 前n个数的和 11 for (var i = 1; i <= n; i++) { 12 thisSum += i; 13 if (thisSum > avg) { 14 console.log("三组中数字最多的一组有:" + (i - 1) + " 个,此时的和为:" + (thisSum - i) + ""); 15 break; 16 } 17 } 18 } 19 </script>
时间: 2024-11-06 04:54:46