輸入任意兩數
一數當底一數當次方項
印出精確值
及位數
我試了好幾次
每次只要數字大到一定的程度
就會變成xxxxxxxxxxxxxE+xxx
沒辦法將他用數字完整表達
有沒有哪位大大可以教教小弟我解決的
感激不盡
2006-11-22 09:38:16 · 6 個解答 · 發問者 ? 1 in 電腦與網際網路 ➔ 程式設計
Private Sub Command1_Click() Dim I, X$, Y$, S$ Do X = InputBox("請輸入底數", "", "123456789123456789") Y = InputBox("請輸入次方數", "", "10") If IsNumeric(X) And IsNumeric(Y) Then If Val(X) >= 0 And Val(Y) >= 0 Then Exit Do End If Loop S = 1 For I = 1 To Y S = strMul(X, S) Next Text1 = SEnd SubFunction strMul$(S1$, S2$) '大數乘法 Dim I%, J%, T%, F%, M%, K$, S$ 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 = F \ 10 Next If T Then S = T & S S = S & String$(Len(S2) - I, "0") If Len(strMul) Then If Len(strMul) < Len(S) Then K = strMul: strMul = S: S = K M = Len(S): T = 0 For J = Len(strMul) To 1 Step -1 If M > 0 Then T = T + Mid$(S, M, 1) F = T + Mid$(strMul, J, 1) Mid$(strMul, J, 1) = F Mod 10 M = M - 1: T = F \ 10 If M = 0 And T = 0 Then Exit For Next If T Then strMul = T & strMul Else strMul = S End If End If Next If Len(strMul) Then Do While Left$(strMul, 1) = 0 strMul = Mid$(strMul, 2) Loop End If If strMul = "" Then strMul = 0End Function
2006-11-22 11:48:50 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋
Private Sub Command1_Click()
Dim Rst As String
Rst = InputBox("數值", "", "5")
NUM = InputBox("平方", "", "3")
aa = Rst
n = Rst
For i = 1 To Val(NUM) - 1
Rst = StrMul(n, aa)
n = Rst
Next i
Debug.Print Rst
Debug.Print "位數"; Len(Rst)
End Sub
'字串相乘函數
Public Function StrMul(ByVal a As String, ByVal b As String) As String
ReDim X(Len(a)), Y(Len(b)), z(Len(a) + Len(b))
'搬字串
For i = 1 To Len(a): X(i) = Mid(a, Len(a) - i + 1, 1): Next
For i = 1 To Len(b): Y(i) = Mid(b, Len(b) - i + 1, 1): Next
'字串陣列相乘
For i = 1 To Len(a)
For j = 1 To Len(b)
z(i + j - 1) = z(i + j - 1) + X(i) * Y(j)
Next j
Next i
'進位
For i = 1 To Len(a) + Len(b)
If z(i) > 9 Then
z(i + 1) = z(i + 1) + z(i) \ 10
z(i) = z(i) Mod 10
End If
Next
StrMul = ""
i = Len(a) + Len(b)
'去除多餘的零
Do While z(i) = 0
i = i - 1
Loop
'將結果搬回字串
For j = i To 1 Step -1
StrMul = StrMul + Trim(Str(z(j)))
Next j
End Function
2006-11-27 15:58:09 · answer #2 · answered by 公路殺手....小古是也 1 · 0⤊ 0⤋
因為別人已經回答了!
所以提供建議,這種問題像是大數加減乘除,都是要用字串來作,不可以用數值來作(指在VB6中).除非用VB.NET才會有那麼大的數.
你先把數值轉字串,然後一對一的處理.這樣懂嗎?
如同別人的回答,就是這樣做的.
2006-11-26 03:12:41 · answer #3 · answered by De-Yu, Lai 3 · 0⤊ 0⤋
2個好像都能解吧
2006-11-24 12:44:24 補充:
10的100次方內答案好像都一樣
2006-11-23 04:42:33 · answer #4 · answered by ? 1 · 0⤊ 0⤋
WJS的為正解。
2006-11-23 10:25:10 補充:
ff_f146的答案不對
2006-11-22 17:51:44 · answer #5 · answered by ? 6 · 0⤊ 0⤋
'拉一個Textbox,Mulitiline設為True,ScrolBars設為1
Private Sub Form_Activate()
Dim N%, M%, i%, j%, Sum2%, K%, Sum$, Temp$
Do
N = InputBox("請輸入底數", "大數次方", "2")
M = InputBox("請輸入次數", "大數次方", "128")
Loop Until N > 0 And M >= 0
Sum = 1
For i = 1 To M
K = 0: Temp = ""
For j = Len(Sum) To 1 Step -1
Sum2 = Val(Mid(Sum, j, 1)) * N + K: Temp = Right(Sum2, 1) & Temp: K = 0
If Sum2 > 9 Then K = Val(Left(Sum2, Len(Sum2) - 1))
Next j
If K = 0 Then Sum = Temp Else Sum = K & Temp
Next i
Text1.Text = N & "^" & M & "=" & Sum
End Sub
2006-11-23 11:03:23 補充:
我能算的數比較小...
還是WJS大強
2006-11-22 10:26:08 · answer #6 · answered by jj0900 1 · 0⤊ 0⤋