Fortran Coder

查看: 17399|回复: 11
打印 上一主题 下一主题

[数值问题] 大数计算

[复制链接]

3

帖子

2

主题

0

精华

新人

F 币
18 元
贡献
10 点
跳转到指定楼层
楼主
发表于 2014-3-5 01:51:44 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式
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



分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

3

帖子

2

主题

0

精华

新人

F 币
18 元
贡献
10 点
沙发
 楼主| 发表于 2014-3-5 10:29:58 | 显示全部楼层
chuxf 发表于 2014-3-5 09:50
可以考虑使用大数模块。

经过计算。100! = 93326215443944152681699238856266700490715968264381621468592 ...

非常感谢啊
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-5-7 23:15

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表