VB程序题1.求S=1+3+5+7+---+99的值.

1个回答

  • 1. Private Sub Command1_Click()

    Dim i As Integer, s As Long

    For i = 1 To 99 Step 2

    res = res + i

    Next i

    Print s

    End Sub

    2. Private Sub Command1_Click()

    Dim i As Integer, N As Long, s As Long

    N = Val(InputBox("请输入N的值"))

    s = 1

    For i = 1 To N

    s = s * i

    Next i

    Print s

    End Sub

    3.

    Private Sub Command1_Click()

    Dim i As Integer, N(7) As Long

    For i = 1 To 7

    N(i) = Val(InputBox("请输入要倒序的数"))

    Next i

    For i = 1 To 7

    Print N(i);

    Next i

    Print

    For i = 7 To 1 Step -1

    Print N(i);

    Next i

    End Sub

    4.

    Private Sub Command1_Click()

    Dim a(10) As Long, max As Long

    Dim i As Integer

    a(1) = Val(Text1.Text)

    a(2) = Val(Text2.Text)

    a(3) = Val(Text3.Text)

    a(4) = Val(Text4.Text)

    a(5) = Val(Text5.Text)

    a(6) = Val(Text6.Text)

    a(7) = Val(Text7.Text)

    a(8) = Val(Text8.Text)

    a(9) = Val(Text9.Text)

    a(10) = Val(Text10.Text)

    For i = 1 To 10

    If a(i) > max Then max = a(i)

    Next i

    Text11.Text = max

    End Su