求1―n输入的正整数之间的奇数之和,vb
答案:1 悬赏:60 手机版
解决时间 2021-11-16 19:10
- 提问者网友:暮烟疏雨之际
- 2021-11-16 12:41
求1―n输入的正整数之间的奇数之和,vb
最佳答案
- 五星知识达人网友:洒脱疯子
- 2021-11-16 13:35
Private Sub Command1_Click()
MsgBox "和为:" & getValue(5)
End Sub
Private Function getValue(ByVal N As Integer) As Integer
Dim i As Integer
Dim sum As Integer
sum = 0
For i = 1 To N
If i Mod 2 = 1 Then
sum = sum + i
End If
Next
getValue = sum
End Function
MsgBox "和为:" & getValue(5)
End Sub
Private Function getValue(ByVal N As Integer) As Integer
Dim i As Integer
Dim sum As Integer
sum = 0
For i = 1 To N
If i Mod 2 = 1 Then
sum = sum + i
End If
Next
getValue = sum
End Function
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯