Private Sub Command1_Click() Dim NowP As Integer NowP = 60 Dim i As Long i = 1 Do While NowP < 70 NowP = 60 * (i + 1.4) i = i + 1 Loop Text1.Text = i
End Sub
跟写方程式一样的.MsgBox (70 - 60) / (60 * 0.14) & "年"
这个是对的 Private Sub Command1_Click() Dim NowP As Integer NowP = 60 Dim i As Long i = 0 Do While NowP < 70 i = i + 1 NowP = NowP * (i + 0.014)
Loop Text1.Text = i
End Sub
晕又错了,这回对了 Private Sub Command1_Click() Dim NowP As Integer NowP = 60 Dim i As Long i = 0 Do While NowP < 70 i = i + 1 NowP = NowP * (1 + 0.014)
Loop Text1.Text = i
End Sub
Private Sub Command1_Click() Dim NowP As Double NowP = 60 Dim i As Long i = 0 Do While NowP < 70 i = i + 1 NowP = NowP * (1 + 0.014)
Loop Text1.Text = i
End Sub
好象不对,NowP = 60 * (i + 1.4)中i应该是不变的,为1吧
Private Sub Form_click() Dim NowP As Single NowP = 60 Dim i As Long i = 0 Do While NowP < 70 NowP = NowP * (1 + 0.014) i = i + 1 Loop Print i End Sub 你看这样对吗
MsgBox (70 - 60) / (60 * 0.14) & "年"
if CInt(Log(70 / 60) / Log(1 + 0.014))<Log(70 / 60) / Log(1 + 0.014) then msgbox(CInt(Log(70 / 60) / Log(1 + 0.014))+1) else msgbox(CInt(Log(70 / 60) / Log(1 + 0.014))) end if 答案就是12年.用这样的算法也可以: Private Sub Form_Load() Dim NowP As Double '不能定义为integer,会影响精度的 NowP = 60 Dim i As Long i = 0 Do While NowP < 70 i = i + 1 NowP = (NowP * (1 + 0.014)) 'NowP = (NowP * (i + 0.014)) 是严重错误的! Loop MsgBox (i & "年")End Sub结果同样是12年.<神行>的算法是错的,只要2年就达到了70亿,这样快地球早人满为患了.
Dim NowP As Integer
NowP = 60
Dim i As Long
i = 1
Do While NowP < 70
NowP = 60 * (i + 1.4)
i = i + 1
Loop
Text1.Text = i
End Sub
Private Sub Command1_Click()
Dim NowP As Integer
NowP = 60
Dim i As Long
i = 0
Do While NowP < 70
i = i + 1
NowP = NowP * (i + 0.014)
Loop
Text1.Text = i
End Sub
Private Sub Command1_Click()
Dim NowP As Integer
NowP = 60
Dim i As Long
i = 0
Do While NowP < 70
i = i + 1
NowP = NowP * (1 + 0.014)
Loop
Text1.Text = i
End Sub
Dim NowP As Double
NowP = 60
Dim i As Long
i = 0
Do While NowP < 70
i = i + 1
NowP = NowP * (1 + 0.014)
Loop
Text1.Text = i
End Sub
Dim NowP As Single
NowP = 60
Dim i As Long
i = 0
Do While NowP < 70
NowP = NowP * (1 + 0.014)
i = i + 1
Loop
Print i
End Sub
你看这样对吗
msgbox(CInt(Log(70 / 60) / Log(1 + 0.014))+1)
else
msgbox(CInt(Log(70 / 60) / Log(1 + 0.014)))
end if
答案就是12年.用这样的算法也可以:
Private Sub Form_Load()
Dim NowP As Double '不能定义为integer,会影响精度的
NowP = 60
Dim i As Long
i = 0
Do While NowP < 70
i = i + 1
NowP = (NowP * (1 + 0.014)) 'NowP = (NowP * (i + 0.014)) 是严重错误的!
Loop
MsgBox (i & "年")End Sub结果同样是12年.<神行>的算法是错的,只要2年就达到了70亿,这样快地球早人满为患了.