输入20个数至数组中,统计其中的奇数个数和偶数的个数
问题描述:
输入20个数至数组中,统计其中的奇数个数和偶数的个数
答
Private Sub Command1_Click()
Dim a(1 To 20) As Integer
Dim i As Integer,t1 As Integer,t2 As Integer
For i = 1 To 20
a(i) = Int(Rnd * 101) '在数组中产生20个100以内的随机数并输出
Print a(i);
Next i
Print
For i = 1 To 20
If a(i) Mod 2 = 0 Then '求出奇数和偶数的个数并赋值给t1和t2
t1 = t1 + 1
Else
t2 = t2 + 1
End If
Next i
Print "偶数个数是" & t1,"奇数个数是" & t2 '输出验证
End Sub