<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> </head> <body> <script type="text/javascript"> var perCount=parseInt(prompt(‘请输入全班人数‘)) var perScores=[]; for(var i=0;i<perCount;i++){ perScores[perScores.length]=parseInt(prompt(‘请输入第‘+(i+1)+‘个人的成绩‘)) } console.log(perScores) var sum=0; var avg=0; var max=perScores[0]; var min=perScores[0]; for(var i=0;i<perScores.length;i++){ sum+=perScores[i] if(max<perScores[i]){ max=perScores[i] } if(min>perScores[i]){ min=perScores[i] } } avg=sum/perScores.length console.log("和为:"+sum) console.log("最小值为:"+min) console.log("最大值为:"+max) console.log("平均值为:"+avg) </script> </body> </html>
原文地址:https://www.cnblogs.com/wwthuanyu/p/10972309.html
时间: 2024-10-14 07:25:19