猴子吃桃子,每天刚好吃一半多一个,到第九天的时候,还剩下一个桃子,问原来一共有多少个桃子?
题目还有这样提示:假设第N天桃子为X,则前一天的桃子为M=(N+1)*2,以此类推,可知第八天的桃子为4,第七天的桃子为10...我想了好久,还是算法不晓得,总是做错下面是我的代码:Private Sub CmdExit_Click()
Unload Me
End SubPrivate Sub CmdOK_Click()
Dim i As Long '天数
Dim intInput As Integer '输入的数据
Dim intOutput As Double '输出的数据
intInput = CInt(TxtInput)
If intInput <= 0 Then
MsgBox "请输入整数...", vbInformation + vbOKOnly, "数据非法"
GoTo LBLEND
End If
就是这里的算法总是算错答案,我头都大了
LBLEND:
End Sub
题目还有这样提示:假设第N天桃子为X,则前一天的桃子为M=(N+1)*2,以此类推,可知第八天的桃子为4,第七天的桃子为10...我想了好久,还是算法不晓得,总是做错下面是我的代码:Private Sub CmdExit_Click()
Unload Me
End SubPrivate Sub CmdOK_Click()
Dim i As Long '天数
Dim intInput As Integer '输入的数据
Dim intOutput As Double '输出的数据
intInput = CInt(TxtInput)
If intInput <= 0 Then
MsgBox "请输入整数...", vbInformation + vbOKOnly, "数据非法"
GoTo LBLEND
End If
就是这里的算法总是算错答案,我头都大了
LBLEND:
End Sub
t = InputBox("天数:")
s = 1
For i = t - 1 To 1 Step -1
s = (s + 1) * 2
Next
MsgBox s
End Sub
ttt = ttt + 1
sum = (sum(ttt) + 1) * 2
Else
sum = 1
End If
End Function典型的递归问题
On Error GoTo MyError
Dim L As Long, i As Long
L = 1
For i = 2 To Val(Text1.Text)
L = 2 * (L + 1)
Next iMyError:
MsgBox L
End Sub
sum = 1
For i = 9 To 2 Step -1
sum = 2 * (sum + 1)
Next
MsgBox sum
Dim t, s, i
t = InputBox("天数:")
s = 1
For i = 8 To t Step -1
s = (s + 1) * 2
Next
MsgBox s
End Sub
我才大一第一个学期
放寒假看看下期开学要学的VB
说实话
我寒假才接触的VB