n! means n (n 1) ... 3 2 1
For example, 10! = 10 9 ... 3 2 1 = 3628800,
and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.
Find the sum of the digits in the number 100!
我的程序:(计算结果有错误)。 求大神帮忙解答,为什么在除以十取余后有错误。有不有更好的算法。
[Fortran] 纯文本查看 复制代码 program Console1
implicit none
integer i
real*8 a
integer b,sum
a=1
do i=1,100
a=a*i
end do
sum=0
do while (a>0)
b=mod(a,10.)
a=a/10.
sum=sum+b
end do
print *, sum
end program Console1
|