用VB该如何编写A,B 两个10位的数字,求AB的平均值C,还有和值D.再求C的每位相加的总和,D的每位相加总和.(小数

1个回答

  • 楼主参考一下:Option Explicit

    Private Function AddNum(ByVal N As Double) As Long

    Dim sNum As String

    Dim S As Long, i As Long

    S = 0: sNum = Fix(N)

    For i = 1 To Len(sNum)

    S = S + Mid$(sNum, i, 1)

    Next

    AddNum = S

    End Function

    Private Sub Command1_Click()

    Dim A#, B#, C#, D#

    Me.Cls

    Randomize

    A = Fix(1000000000# + 8999999999# * Rnd())

    B = Fix(1000000000# + 8999999999# * Rnd())

    D = A + B

    C = D / 2

    Print "原始值 A = " A

    Print "原始值 B = " B

    Print "平均值 C = " C

    Print " 和值 D = " D

    Print "C 的整部分之和为:" AddNum(C)

    Print "D 的整部分之和为:" AddNum(D)

    End Sub