编写一个vba程序,输出任意10个数中负数的个数,偶数的个数,奇数的和
2个回答
展开全部
Dim arr(1 To 10) As Long
Dim FuShu As Integer, FuShuHe As Long
Dim Oushu As Integer, OuShuHe As Long
Dim JiShu As Integer, JishuHe As Long
Dim i As Integer
For i = 1 To 10
arr(i) = InputBox("第" & i & "个数的值", "输入", 0)
Next
For i = 1 To 10
If arr(i) < 0 Then
FuShu = FuShu + 1
FuShuHe = FuShuHe + arr(i)
End If
If Int(arr(i) / 2) * 2 = arr(i) Then
Oushu = Oushu + 1
OuShuHe = OuShuHe + arr(i)
Else
JiShu = JiShu + 1
JishuHe = JishuHe + arr(i)
End If
Next
MsgBox "负数有" & FuShu & "个,负数和为" & FuShuHe & ";偶数有" & Oushu & "个,偶数和为" & OuShuHe & ";奇数有" & JiShu & "个,奇数的和为" & JishuHe & "。"
展开全部
试试下面的代码,是用VB写的,可能需要一些改动:
添加一个按钮
Private Sub Command1_Click()
Dim a(9) As Long, i As Integer, k As Integer, s As Integer, n As Integer
For i = 0 To 9
a(i) = Val(InputBox("请输入任意一个数"))
If a(i) Mod 2 = 0 Then k = k + 1
If a(i) Mod 2 <> 0 Then s = s + a(i)
If a(i) < 0 Then n = n + 1
Next i
Print "偶数的个数为:" & k
Print "负数的个数为:" & n
Print "奇数的和为:" & s
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询