大数的阶乘

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 jennyvenus 的 blog

public function factorial(intc as integer) as string
on error goto myerr:
    dim inta() as integer, intt() as integer, i as integer
    dim j as integer, intr as integer
    redim inta(20), intt(20)
    if intc < 2 then exit function
    intr = 20
    inta(0) = 1
    for i = 2 to intc
        for j = 0 to intr
            intt(j) = inta(j) * i
        next j
        j = 0
        do until j > intr
            inta(j) = intt(j) mod 10
            if intt(j) >= 10 then intt(j + 1) = intt(j + 1) + intt(j) \ 10
            j = j + 1
        loop
    next i
   
    do while true
        j = j - 1
        if inta(j) > 0 then exit do
    loop
   
    for j = j to 0 step -1
        factorial = factorial & inta(j)
    next j
    exit function
myerr:
    if err.number = 9 then
        intr = intr + 20
        redim preserve inta(intr)
        redim preserve intt(intr)
        resume
    else
        msgbox "unknow err:" & err.description & ":" & err.number, vbcritical + vbokonly
    end if
end function

本文关键:none
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top