vba编程 求1+2+3...+100的值
答案:3 悬赏:80 手机版
解决时间 2021-03-23 22:29
- 提问者网友:难遇难求
- 2021-03-23 15:27
vba编程 求1+2+3...+100的值
最佳答案
- 五星知识达人网友:老鼠爱大米
- 2021-03-23 16:28
sum=0
for i=1 to 100
sum=sum+i
next
for i=1 to 100
sum=sum+i
next
全部回答
- 1楼网友:白昼之月
- 2021-03-23 17:23
Private Sub Command1_Click()
Dim a, sum As Long
sum = 0
For a = 1 To 100
sum = sum + a
Next a
Print sum
End Sub
一共有6种方法
1
sum=0
for i = 1 to n
sum = sum+i
next i
2
i = 0
Do While i <= n
Sum = Sum + i
i = i + 1
Loop
3
i = 0
Do Until i > n
Sum = Sum + i
i = i + 1
Loop
4
Sum = (1 + n) * n / 2
5
While i <= n
Sum = Sum + i
i = i + 1
Wend
6
While i > n
Sum = Sum + i
i = i + 1
Wend
Dim a, sum As Long
sum = 0
For a = 1 To 100
sum = sum + a
Next a
Print sum
End Sub
一共有6种方法
1
sum=0
for i = 1 to n
sum = sum+i
next i
2
i = 0
Do While i <= n
Sum = Sum + i
i = i + 1
Loop
3
i = 0
Do Until i > n
Sum = Sum + i
i = i + 1
Loop
4
Sum = (1 + n) * n / 2
5
While i <= n
Sum = Sum + i
i = i + 1
Wend
6
While i > n
Sum = Sum + i
i = i + 1
Wend
- 2楼网友:野味小生
- 2021-03-23 17:00
Sub aa()
Dim i&, x&
i = 1
Do While i < 101
x = x + i
i = i + 1
Loop
MsgBox x
End Sub
或
Sub aa1()
Dim i&, x&
For i = 1 To 100
x = x + i
Next i
MsgBox x
End Sub
两种循环方式,值为5050
Dim i&, x&
i = 1
Do While i < 101
x = x + i
i = i + 1
Loop
MsgBox x
End Sub
或
Sub aa1()
Dim i&, x&
For i = 1 To 100
x = x + i
Next i
MsgBox x
End Sub
两种循环方式,值为5050
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯