回复 88楼 wmf2014
这回好!复制下来了,谢谢您!学习学习,非常感谢!
Public Function MPC(ByVal d1 As String, ByVal d2 As String) As String '大数减法d1-d2,如果d2>d1则交换,非法字符当字符0处理,不识别负数 Dim a As String, i As Integer If mComp(d1, d2) < 0 Then '确保被减数大于减数 MPC = MPC(d2, d1) '这里可根据需要添加负号输出负数 Exit Function '其实负数还是要处理的,我经常取逆元取到负数,这时就需要加一次n-1 End If a = "" For i = 1 To Len(d2) a = a & (9 - Val(Mid(d2, i, 1))) '对减数按位取反 Next For i = Len(d2) + 1 To Len(d1) a = "9" + a Next a = MPC1(d1, MPC1(a, "1")) '调整该减数为对应十进制补数并和被加数相加 If Len(a) > Len(d1) Then a = Right(a, Len(d1)) '去掉进位 For i = 1 To Len(a) If Mid(a, i, 1) <> "0" Then Exit For Next a = Right(a, Len(a) + 1 - i) '消前导0 If a = "" Then a = "0" MPC = a End Function