摘要: [Visual Basic 6.0] 大整數運算 大數加法 (使用 Array 字串)
[Visual Basic 6.0] 大整數運算 大數加法 (使用 Array 字串)
Private Sub Command1_Click()
Text3 = ""
ReDim TempArray(999)
K = 0
For i = Len(Text1) To 1 Step -1
TempArray(K) = Mid(Text1, i, 1)
K = K + 1
Next i
K = 0
For i = Len(Text2) To 1 Step -1
Temp = Val(TempArray(K)) + Val(Mid(Text2, i, 1))
TempArray(K) = Temp Mod 10
K = K + 1
TempArray(K) = Val(TempArray(K)) + Val(Temp \ 10)
Next i
For i = 0 To UBound(TempArray)
If Val(TempArray(i)) > 9 Then
Temp = TempArray(i)
TempArray(K) = Temp Mod 10
K = K + 1
TempArray(K) = Val(TempArray(K)) + Val(Temp \ 10)
End If
Next i
For i = UBound(TempArray) To 0 Step -1
Text3 = Text3 & TempArray(i)
Next i
Do Until Val(Mid(Text3, 1, 1)) <> 0
Text3 = Mid(Text3, 2)
Loop
End Sub
#0xDe 從分享中學習
#Facebook:ProgrammerDe (https://www.facebook.com/MicrosoftDes) 有問題歡迎提問