VB中用随机数函数产生100个100~300之间的整数,在窗体上输出能被3 整除的数的和及个数.求代码啊...

1个回答

  • Private Sub Command1_Click()

    Dim a() As Integer,i,j,m,n As Integer

    Print "产生100个100~300之间的整数"

    Randomize

    For i = 1 To 100

    j = Int(Rnd * 201) + 100

    If j Mod 3 = 0 Then

    n = n + 1

    ReDim Preserve a(n)

    a(n) = j

    End If

    Print j;

    m = m + 1

    If m Mod 10 = 0 Then Print

    Next

    Print

    Print "能被3整除的数"

    m = 0

    For i = 1 To n

    Print a(i);

    m = m + 1

    If m Mod 10 = 0 Then Print

    j = j + a(i)

    Next

    Print

    Print "个数="; n

    Print "和="; j

    End Su