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

求2 的 n次方
附註:需要用到長整數乘法的計算
希望能在12點以前(明天考式的內容= =)

2006-06-21 18:44:55 · 1 個解答 · 發問者 Mini 1 in 電腦與網際網路 程式設計

1 個解答

Private Sub Command1_Click()    Dim N%, I%, Sum$        Do      N = Int(Val(InputBox("請輸入正整數")))    Loop Until N >= 0    Sum = 1: Cls    For I = 1 To N        Sum = Mult(Sum, "2")    Next    Print "2^"; N; "="; SumEnd SubFunction Mult(ByVal Str1 As String, ByVal Str2 As String) As String '大數乘法    Dim I%, J%, S$, St$, M%, T%        Mult = "0"    For I = Len(Str1) To 1 Step -1        S = "": T = 0: M = Mid$(Str1, I, 1)        For J = Len(Str2) To 1 Step -1            St = Format(M * Mid$(Str2, J, 1) + T, "00")            T = Left$(St, 1): S = Right$(St, 1) & S        Next        If T Then S = T & S        S = S & String$(Len(Str1) - I, "0")        Mult = mADD(Mult, S)    NextEnd FunctionFunction mADD(ByVal S1 As String, ByVal S2 As String) As String '大數加法    Dim I%, St$, T%, X%        If Len(S1) < Len(S2) Then St = S1: S1 = S2: S2 = St    X = Len(S2): mADD = S1    For I = Len(S1) To 1 Step -1        If X > 0 Then           St = Int(Mid$(S1, I, 1)) + Int(Mid$(S2, X, 1)) + T           X = X - 1        Else           If T = 0 Then Exit Function           St = Int(Mid$(S1, I, 1)) + T        End If        T = -1 * (Len(St) > 1)        Mid$(mADD, I, 1) = Right$(St, 1)    Next    If T Then mADD = "1" & mADDEnd Function

2006-06-21 20:15:38 · answer #1 · answered by W.J.S. 7 · 0 0

fedest.com, questions and answers