<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>计算1+1/3+1/5+...+1/(2n-1)累加和</title>
<script type="text/javascript">
function compute(){
var n = document.getElementById("n").value;
var result = document.getElementById("result");
var sum = 0;
for(var i=1; i<=n; i++){
sum += 1/(2*i-1);
}
result.value = sum;
}
</script>
</head>
<body>
<div style="width:300px;height:200px;border:groove 8px #009900;line-height:2em;margin:50px auto;text-align:center" >
<h3 style="padding:10px; color:#0000cc">计算累加和</h3>
<form>
输入数N:
<input id="n" type="text" value="" />
<br/>
累加和 :
<input id="result" type="text" value="" />
<br/>
<input id="sum" type="button" value="计算累加和" onClick="compute()" />
<input id="reset" type="reset" value="重置" />
</form>
</div>
</body>
</html>
找人做作业才给5分啊,再说不怕你们老师上网搜么?很容易暴露的。