English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

試寫一程式執行兩多位數相乘之運算,多位數之位數值必須多於10位數。
......求助各位怎麼解這個問題呢

2006-12-24 17:26:43 · 2 個解答 · 發問者 千雲 1 in 電腦與網際網路 程式設計

2 個解答


'版本VB6.0
'只計算整數

Private Sub Command1_Click()
MsgBox Mul("12345678912", "12345678910")
End Sub

Function Mul$(S1$, S2$)
Dim I%, J%, T%, F%, M%, K$, S$, B As Boolean

B = Val(S1) < 0 Xor Val(S2) < 0
S1 = Replace(S1, "-", "")
S2 = Replace(S2, "-", "")
For I = Len(S2) To 1 Step -1
M = Mid(S2, I, 1)
If M Then
T = 0
S = ""
For J = Len(S1) To 1 Step -1
F = M * Mid(S1, J, 1) + T
S = F Mod 10 & S: T = Int(F / 10)
Next
If T Then S = T & S
S = S & String(Len(S2) - I, "0")
If Len(Mul) Then
If Len(Mul) < Len(S) Then K = Mul: Mul = S: S = K
M = Len(S)
T = 0
For J = Len(Mul) To 1 Step -1
If M > 0 Then T = T + Mid(S, M, 1)
F = T + Mid(Mul, J, 1)
Mid(Mul, J, 1) = F Mod 10
M = M - 1
T = Int(F / 10)
If M = 0 And T = 0 Then Exit For
Next
If T Then Mul = T & Mul
Else
Mul = S
End If
End If
Next
If Len(Mul) Then
Do While Left(Mul, 1) = 0
Mul = Mid(Mul, 2)
Loop
End If
If Mul = "" Then
Mul = 0
Else
If B Then Mul = "-" & Mul
End If

End Function

2006-12-24 20:38:26 · answer #1 · answered by W.J.S. 7 · 0 0

到下面的網址看看吧

▶▶http://*****

2014-09-03 19:47:59 · answer #2 · answered by Anonymous · 0 0

fedest.com, questions and answers