html language

2013-06-02 6:58 am
please write a program to generate the sum of all even numbers between 1and 100?

回答 (1)

2013-06-02 9:26 pm
✔ 最佳答案
<html>
<head>
<title></title>
<script type="text/javascript">

function onload() {
var result = sumOfNumberBetween(2, 100);
document.getElementById("result").innerHTML = result;
return true;
}

function sumOfNumberBetween(min, max) {
var result = 0;
for (var i = min; i <= max; i += 2) {
result += i;
}
return result;
}
</script>
</head>
<body onload="onload()">
<div>
The sum of all even number between 1 and 100 is <span id="result" />.
</div>
</body>
</html>


收錄日期: 2021-04-28 14:32:56
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20130601000051KK00375

檢視 Wayback Machine 備份