主题:n的阶乘(高精度)
我要独立
[专家分:40] 发布于 2010-11-27 12:56:00
求n的阶乘高精度的程序!
各位高手来写一写啊
最后更新于:2010-11-27 14:20:00
回复列表 (共8个回复)
沙发
huangyb731 [专家分:630] 发布于 2010-11-27 18:48:00
cls
input N#
Z#=1
for I#=1 to N#
Z#=Z#*I#
next
print N#;"!="Z#
end
50分!
板凳
huangyb731 [专家分:630] 发布于 2010-11-27 19:24:00
先给30分,再选为最佳答案
3 楼
301梯子梯子 [专家分:0] 发布于 2010-11-27 21:01:00
淡淡的
4 楼
幽灵密码 [专家分:3510] 发布于 2010-11-27 21:02:00
CLS
INPUT n
DIM a(n)
a(1) = 1
FOR i = 1 TO n
g = 0
FOR j = 1 TO n
t = a(j) * i + g
g = t \ 10
a(j) = t MOD 10
NEXT j
NEXT i
DO UNTIL a(n) <> 0
n = n - 1
LOOP
FOR i = n TO 1 STEP -1
PRINT LTRIM$(STR$(a(i)));
NEXT i
5 楼
huangyb731 [专家分:630] 发布于 2010-11-28 13:39:00
( ⊙ o ⊙ )啊!
6 楼
idealguy [专家分:110] 发布于 2011-11-24 00:28:00
[em13]
7 楼
idealguy [专家分:110] 发布于 2012-01-01 18:01:00
该程序有重大错误:只能算N<=24
(因为,当N>24,N!的位数大于N :D )
8 楼
idealguy [专家分:110] 发布于 2012-01-01 19:22:00
一个可用的程序:
[font=宋体]
DEFINT A-Z
'
DIM A(8920) AS INTEGER
CLS
INPUT "N=[2..10000], N=", N
IF N > 10000 THEN N = 10000
T1! = TIMER
A(1) = 1
Nm = 1 '结果位数
FOR i& = 1 TO N
g = 0
FOR j = 1 TO Nm
E& = A(j) * i& + g
g = E& \ 10000
A(j) = E& - g * 10000&
NEXT j
IF g > 0 THEN
Nm = Nm + 1
A(Nm) = g
END IF
NEXT i&
'
T$ = LTRIM$(STR$(A(Nm)))
L& = LEN(T$)
PRINT T$;
FOR K = Nm - 1 TO 1 STEP -1
PRINT RIGHT$("000" + LTRIM$(STR$(A(K))), 4);
L& = L& + 4
NEXT K
PRINT
PRINT "Total Digits:"; L&; " Time="; TIMER - T1!; "s"
END
[/font]
我来回复