vb多位數計算問題

2008-04-28 1:23 pm
如果要計算一些超出"double"範圍的數要怎麼做?
如計算"3的1000次方" 或者 "400!"
是否需要寫一個程式來計算, 如是者程式要怎樣寫?

回答 (3)

2008-05-06 7:49 pm
✔ 最佳答案
Dim i, j As Integer
Dim proNum1, oriNum, newNum, proNum2 As String
oriNum = "1"
newNum = ""
proNum1 = ""
proNum2 = ""
For i = 1 To Val(textbox1.Text)
System.Windows.Forms.Application.DoEvents()
For j = 1 To Len(oriNum)
proNum1 = CStr(Val(Mid(oriNum, Len(oriNum) - j + 1, 1)) * 3 + Val(proNum2))
If Len(proNum1) = 1 Then
proNum2 = ""
ElseIf Len(proNum1) = 2 Then
proNum2 = V.Left(proNum1, 1)
proNum1 = V.Right(proNum1, 1)
End If
newNum = proNum1 & newNum
If (j = Len(oriNum)) And (Len(proNum2) = 1) Then newNum = proNum2 & newNum
Next
oriNum = newNum
newNum = ""
proNum2 = ""
Next
參考: 自己
2008-04-28 7:17 pm
我已試過但計不出答案.
請問你是如何做到計得出結果?
可以告訴我程式碼 嗎?

2008-04-29 07:44:10 補充:
其實我是找能計算這些數的程式.
我現在知道原來這些叫"大數運算".

2008-04-29 07:49:53 補充:
我之前曾經見過有人寫了一個可以計算2的任意次方的程式,我試過計算2^10000,它都能將答案每一個數字顯示出來,可惜我不知道它的vb程式碼.
2008-04-28 4:30 pm
Do you have to do this in VB.net?
Java has a BigInteger class that can calculate these numbers quite easily.
3^1000 will have about 477 digits and 400! about 868 digits.
It is possible to do it in any language, but will involve a litlle programming.

2008-04-29 07:29:10 補充:
Sorry, 3^1000 has 477 digits (1000log3=1000*0.4771=477.1) The first fiew digits are:
13220708194808066368904552597521443659654...
Are you looking for the answer or the program to do it?

2008-04-29 09:57:08 補充:
You can use strings to represent the numbers, or else use an array of characters. You'd have to make addition and multiplication methods using these data structures.


收錄日期: 2021-04-13 15:29:39
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20080428000051KK00350

檢視 Wayback Machine 備份