输入班级人数,输入成绩--求总成绩、平均值、最小值、最大值

		//输入班级人数
		var perCount = parseInt(prompt("请输入班级人数:"));
        var perScore = [];
        for (var i = 1; i <= perCount; i++) {
        	//输入成绩并将成绩存储在空数组里
            perScore[perScore.length] = Number(prompt("请输入第" + i + "个人成绩:"));
        }
        var sum = 0;
        var avg;
        var maxScore = perScore[0];
        var minScore = perScore[0];
        for (var j = 0; j < perScore.length; j++) {
            sum += perScore[j];
            if (maxScore < perScore[j]) {
                maxScore = perScore[j];
            } else if (minScore > perScore) {
                minScore = perScore[j];
            }
        }
        avg = sum / perScore.length;
        console.log("总成绩为:" + sum);
        console.log("平均成绩为:" + avg);
        console.log("最大成绩为:" + maxScore);
        console.log("最小成绩为:" + minScore);
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页