用递归求1+2+3+......+n VB程序
答案:3 悬赏:40 手机版
解决时间 2021-04-16 02:15
- 提问者网友:听门外雪花风
- 2021-04-15 12:50
用递归求1+2+3+......+n VB程序
最佳答案
- 五星知识达人网友:不如潦草
- 2021-04-15 13:42
Private Sub Command1_Click()
Dim a As Integer
Dim b As Integer
Dim sum As Integer
a = 1
b = 100
sum = (a + b) * (b / 2)
Print sum
End Sub
Dim a As Integer
Dim b As Integer
Dim sum As Integer
a = 1
b = 100
sum = (a + b) * (b / 2)
Print sum
End Sub
全部回答
- 1楼网友:鱼忧
- 2021-04-15 16:15
Dim sum As Integer
Private Sub CommandButton1_Click() sum = 0 he (100) commandbutton1.caption= sum
End Sub
Sub he(n) If n Then sum = sum + n n = n - 1 he (n) End If
End Sub
Private Sub UserForm_Click()
End Sub
- 2楼网友:鱼忧
- 2021-04-15 15:19
要用递归,也就是要把大问题分成小问题
1+2==1+(1+1)
99+100=99+(99+1) N+(N+1)
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯