请教VB高手们
发布网友
发布时间:2024-10-16 12:21
我来回答
共6个回答
热心网友
时间:2024-11-09 18:16
OK,我前面说错了,更正如下:
如果以科学计数法计算的话大概是这样:
3456^321
=10^(321*log3456/log10)
=10^1135.882168552
=7.62374834347224E+1135
以VB计算精确结果时,可自定义一个Long型数组,每个数组元素代表一个万进制的位,即每次将每个数组内的数值乘以3456,然后将超出10000的部分除以10000后进到上一位,也就是下一数组元素,将余数保留在当前位上,即当前数组元素中,循环运算321次后即得到最终结果,最后将最终结果使用字符串连接输出。
Private Sub Form_Load()
Dim result() As Long 'Long型数组,每个数组元素为一个“万进制”的位
Dim i As Integer, j As Integer '计数器
Dim lUbound As Integer '万进制的总位数
lUbound = 0
ReDim result(0) As Long
result(0) = 3456 '初始值为3456
For i = 1 To 320 '循环运算320次
For j = 0 To lUbound '将每个数组元素中的数值乘以3456
result(j) = result(j) * 3456
Next
For j = 0 To UBound(result) '检查每个数组元素中的数值
If result(j) > 10000 Then '如果数值大于10000,则进位
If j = lUbound Then '在进位前检查数组边界
lUbound = lUbound + 1
ReDim Preserve result(lUbound)
End If
'进位的计算很简单,将大于10000的部分除以10000后进到上一位
result(j + 1) = result(j + 1) + result(j) \ 10000
'在原位上保留除以10000的余数
result(j) = result(j) Mod 10000
End If
Next
Next
'将全部结果连接到字符串中输出
For i = 0 To lUbound - 1
s = Format(result(i), "0000") & s
Next
s = result(i) & s
Text1.Text = s
Label1.Caption = "结果位数:" & Len(s)
End Sub
结果为:
76237483434840499889712426626096473963909931068247124172638199410539220053201610161450464002066939280638926925260420270154405231799447495245320436731301665931283240952660137358086907368044339121830531635848144441450568772821508287993467666438181243885755554898792836015603432708062302977998759211291131951767699978019004975330695697054793042155499221429969567052855745935136659823726845527843445136329342404766218345920692702081484144369600981406896399390541306496661397639380287227282800034638166780330382244829304071880825807023908154340005769742217325779028244644751599980322315632760625170290738351846477618573880996099932351295352950325271332844044331635038371782148986666758477217714762990062214571539825801641194903714821706518619256060414384827023948648226598364217388537480320237522075748433090727539744419610978258782969527316532158732245819802526035446474729194329275609908892767737827957808489590052473741556582857491245840372887253113107060668452433190374614955680014306887060608525003501743593527880304666492270653920664564390716079811354086365433698310713603357154393047253283255434103929871965354687684095494867235373056
热心网友
时间:2024-11-09 18:16
看那个fisher的吧
热心网友
时间:2024-11-09 18:17
如果你想算出结果,我想普通计算机不行,内存太小会溢出,你可以找超级计算机“天河”试试,应该可以,
热心网友
时间:2024-11-09 18:17
double都数据溢出
热心网友
时间:2024-11-09 18:18
用字符的方式模仿乘法计算,这方式在C、C++语言比较常见,但VB中不常见
热心网友
时间:2024-11-09 18:19
膜拜 小fisher!
我用模拟笔算写的乘法算法,用在这个题目里就是不断乘3456,效率比你低近百倍,编译后更是低几百倍(优化全开)
真牛!抽空要吃透你的算法