'-------------------------------------------------
'(1)求奇数的和
Dim oddSum As Integer '奇数的和
oddSum = 0
For i = 1 To 10
If i Mod 2 <> 0 Then oddSum = oddSum + i
Next i
'-------------------------------------------------
'-------------------------------------------------
'(2)求偶数的和
Dim evenSum As Integer '偶数的和
evenSum = 0
For i = 1 To 10
If i Mod 2 = 0 Then evenSum = evenSum + i
Next i
'-------------------------------------------------
'-------------------------------------------------
'(3)求质数的和
Dim primeSum As Integer '质数的和
primeSum = 0
For i = 2 To 10
isPrime = 1
For j = 2 To Int(i / 2)
If i Mod j = 0 Then isPrime = 0 '如果数有大于2小于本身的约数返回0(否)
Next j
If isPrime Then primeSum = primeSum + i
Next i
'-------------------------------------------------
温馨提示:答案为网友推荐,仅供参考