两个多位数相乘

Option Base 1

Private Sub Command1_Click()

    Dim M As String
    Dim n As String
   
    M = Text1.Text
    n = Text2.Text
   
    Dim number1() As Byte
    Dim number2() As Byte
    ReDim number1(Len(n))
    ReDim number2(Len(M))
   
    Dim index As Byte
   
    For index = 1 To Len(n) Step 1
    number1(index) = Mid(n, index, 1)
    Next index
   
    For index = 1 To Len(M) Step 1
    number2(index) = Mid(M, index, 1)
    Next index
   
    Dim tesult() As Byte
    ReDim Result(Len(n) + Len(M))
   
    Dim MCarry As Byte
    Dim Acarry As Byte
    Dim remainder As Integer
   
    Dim i As Integer, j As Integer
    Dim Mtemp As Integer, Atempm As Integer
   
       
         For i = Len(n) To 1 Step -1
           For j = Len(M) To 1 Step -1
           Mtemp = number1(j) * number2(i) + MCarry
            MCarry = Mtemp \ 10
            remainder = Mtemp Mod 10
            Atemp = remainder + Result(i + j) + Acarry
            Acarry = Atemp \ 10
            Result(i + j) = Atemp Mod 10
    Next j
            Result(i) = MCarry + Acarry
            MCarry = 0
            Acarry = 0
    Next i
 
         Dim Mstr  As String
 
         For index = 1 To Len(n) + Len(M)
         Mstr = Mstr & Str(Result(index))
  Next
 
      Label3.Caption = Mstr

End Sub

    
    

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值