编写应用程序,输入10个数到数组中,并统计其中正数的个数、正数的和以及负数的个数、负数的和 是VB
Option Explicit
Dim a(10)
Private Sub InPutVal_cmd_Click()
Dim i As Integer
For i = 0 To 9
a(i) = InputBox("请输入第" & i + 1 & "个数字", "输入数字")
Next i
End Sub
Private Sub TotalOut_cmd_Click()
Dim i As Integer
Dim countZ As Integer
Dim countF As Integer
Dim SumZ As Double
Dim SumF As Double
For i = 0 To 9
If a(i) < 0 Then
countF = countF + 1
SumF = SumF + a(i)
ElseIf a(i) > 0 Then
countZ = countZ + 1
SumZ = SumZ + a(i)
End If
Print "第" & i + 1 & "数为: " & a(i)
Next i
Print "正数个数为:" & countZ, "负数个数为:" & countF
Print "正数之和为:" & SumZ, "负数之和为:" & SumF
End Sub