标题:[讨论]一个小学数学题如何编程?
只看楼主
心中有剑
Rank: 2
等 级:新手上路
威 望:5
帖 子:611
专家分:0
注 册:2007-5-18
得分:0 
[CODE] Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim Sum = 0
For i = 1 To 99
Sum = Sum + 1 / (i * (i + 1))
Next
Label1.Text = Sum
End Sub[/CODE]

答案就是0.99啊 没有错的啊!何必伪造呢
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim Sum As Double = 0
For i = 1 To 99
Sum = Sum + 1 / (i * (i + 1))
Next
Label1.Text = Sum
End Sub
double的精度就够了, single的精度不够!

[此贴子已经被作者于2007-8-29 9:19:21编辑过]


2007-08-29 09:18



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-73388-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.098244 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved