access vba 编程 请高手发个编程代码。谢谢。谢谢、
2.计算1到100的所有偶数的和(即计算2+4+…+100).(1)使用For语句实现.(2)使用While语句实现.(3)使用Do语句实现.3.设计一程序,计算出1至2...
2. 计算1到100的所有偶数的和(即计算2+4+…+100).
(1) 使用For语句实现.
(2) 使用While语句实现.
(3) 使用Do语句实现.
3. 设计一程序, 计算出1至200能被3整除的所有数, 并统计个数. 展开
(1) 使用For语句实现.
(2) 使用While语句实现.
(3) 使用Do语句实现.
3. 设计一程序, 计算出1至200能被3整除的所有数, 并统计个数. 展开
1个回答
展开全部
'计算1到100的所有偶数的和
Function sum100() As Integer
Dim i As Integer
Dim iSum As Integer
iSum = 0
For i = 2 To 100 Step 2
iSum = iSum + i
Next i
sum100 = iSum
MsgBox (iSum)
iSum = 0
i = 2
While (i <= 100)
iSum = iSum + i
i = i + 2
Wend
MsgBox (iSum)
iSum = 0
i = 2
Do Until (i > 100)
iSum = iSum + i
i = i + 2
Loop
MsgBox (iSum)
sum100 = iSum
End Function
'计算出1至200能被3整除的所有数, 并统计个数
Function sum200d3() As Integer
Dim i As Integer
Dim iCount As Integer
Dim sNum As String
iCount = 0
sNum = "1至200能被3整除的所有数:"
For i = 1 To 200
If i Mod 3 = 0 Then
sNum = sNum + Str(i) + ", "
iCount = iCount + 1
End If
Next i
MsgBox (sNum + "个数为:" + Str(iCount))
End Function
'附言: 小鬼, 作业要自己完成啊!
Function sum100() As Integer
Dim i As Integer
Dim iSum As Integer
iSum = 0
For i = 2 To 100 Step 2
iSum = iSum + i
Next i
sum100 = iSum
MsgBox (iSum)
iSum = 0
i = 2
While (i <= 100)
iSum = iSum + i
i = i + 2
Wend
MsgBox (iSum)
iSum = 0
i = 2
Do Until (i > 100)
iSum = iSum + i
i = i + 2
Loop
MsgBox (iSum)
sum100 = iSum
End Function
'计算出1至200能被3整除的所有数, 并统计个数
Function sum200d3() As Integer
Dim i As Integer
Dim iCount As Integer
Dim sNum As String
iCount = 0
sNum = "1至200能被3整除的所有数:"
For i = 1 To 200
If i Mod 3 = 0 Then
sNum = sNum + Str(i) + ", "
iCount = iCount + 1
End If
Next i
MsgBox (sNum + "个数为:" + Str(iCount))
End Function
'附言: 小鬼, 作业要自己完成啊!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询