VB题:定义一个具有20个元素的一维数组,并对其随机赋值,然后求出其中元素值为奇数的元素的和

1个回答

  • 20个元素,每5个打印一行

    Private Sub Command1_Click()

    Dim a(20) As Integer,s As Integer

    For i = 1 To 20

    a(i) = Int(Rnd * 1000) + 1

    Print a(i);

    If i Mod 5 = 0 Then Print

    Next i

    For i = 1 To 20

    If a(i) Mod 2 0 Then

    s = s + a(i)

    End If

    Next i

    Print " 奇数和为:" & s

    End Su