第1个题:
Private Sub Command1_Click()
Dim i As Integer
Dim j As Integer
Dim t As Integer '奇数个数
Dim s As Integer '奇数合计
Dim m As Double '奇数平均
For i = 1 To 20
Randomize
j = Int(101 * Rnd + 100)
If j Mod 2 = 1 Then '奇数
Print j
s = s + j
t = t + 1
End If
Next
m = s / t
Print "奇数平均:" & m
End Sub
第2个题
Private Sub Command2_Click()
Dim i As Long
Dim j As Long
Dim s1 As Long '偶数合计
Dim s2 As Long '奇数合计
For i = 1 To 10
j = Val(InputBox("", "输入第" & i & "个数"))
If j Mod 2 = 0 Then
s1 = s1 + j
Else
s2 = s2 + j
End If
Next
Print "偶数合计:" & s1
Print "奇数合计:" & s2
End Sub
第3个题:
Private Sub Command3_Click()
Dim i As Long
Dim j As Long
Dim max As Long '最大
Dim min As Long '最小
For i = 1 To 10
j = Val(InputBox("", "输入第" & i & "个数"))
If i = 1 Then
max = j
min = j
End If
If max < j Then
max = j
End If
If min > j Then
max = j
End If
Next
Print "最大数:" & max
Print "最小数:" & min
End Sub
很简单啊,自己查查资料就搞定了,上学多学点东西还是很好的,学费不是白交的。