Деление сверхбольших чисел - VB
Формулировка задачи:
Доброго времени суток!!!
Кто-нибудь знает алгоритм деления сверхбольших чисел(более 100 цифр)?
Решение задачи: «Деление сверхбольших чисел»
textual
Листинг программы
'Сравнение 2-х положительных целых сверхбольших чисел в строковом формате Function StrCompEx(m1 As String, m2 As String) As Integer StrCompEx = Sgn(Len(m1) - Len(m2)) If StrCompEx = 0 Then StrCompEx = StrComp(m1, m2) End Function 'деление Function div(m1 As String, m2 As String) As String Dim dm As String Dim i1 As Long, i2 As Long, L1 As Long, L2 As Long L1 = Len(m1): L2 = Len(m2) dm = Mid$(m1, 1, L2) For i1 = 1 To L1 - L2 + 1 i2 = 0 While StrCompEx(dm, m2) >= 0 dm = dif(dm, m2) i2 = i2 + 1 Wend if dm="0"then dm="" dm = dm & Mid$(m1, L2 + i1, 1) div = div & IIf(Len(div) = 0 And i2 = 0, "", i2) Next i1 End Function 'вычитание Function dif(m1 As String, m2 As String) As String Dim a() As String, n As Byte Dim i1 As Long, i2 As Long, L1 As Long, L2 As Long L1 = Len(m1): L2 = Len(m2) ReDim a(L1) For i1 = L1 To 1 Step -1 If L2 > 0 Then a(i1) = Mid$(m1, i1, 1) - Mid$(m2, L2, 1) - i2 L2 = L2 - 1 Else a(i1) = Mid$(m1, i1, 1) - i2 End If If a(i1) < 0 Then a(i1) = a(i1) + 10 i2 = 1 Else i2 = 0 End If Next i1 For i1 = 1 To L1 - 1 If a(i1) = "0" Then a(i1) = "" Else Exit For Next i1 dif = Join(a, "") End Function 'умножение Function mul(m1 As String, m2 As String) As String Dim a() As String, n As Byte Dim i1 As Long, i2 As Long, L1 As Long, L2 As Long L1 = Len(m1): L2 = Len(m2) ReDim a(L1 + L2) For i2 = L2 To 1 Step -1 n = Mid$(m2, i2, 1) For i1 = L1 To 1 Step -1 a(i1 + i2) = Val(a(i1 + i2)) + n * Mid$(m1, i1, 1) If a(i1 + i2) > 9 Then a(i1 + i2 - 1) = Val(a(i1 + i2 - 1)) + a(i1 + i2) \ 10 a(i1 + i2) = a(i1 + i2) Mod 10 End If Next i1 Next i2 mul = Join(a, "") End Function
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д