楚香饭 发表于 2020-4-16 09:02 谢谢大佬!!!! |
|
本帖最后由 楚香饭 于 2020-4-16 09:03 编辑 一直除10,直到小于10为止 [Fortran] syntaxhighlighter_viewsource syntaxhighlighter_copycode Program www_fcode_cn
Implicit None
integer :: a
read(*,*) a
write(*,*) getDecimalismSum(a)
contains
Integer Function getDecimalismSum(x) result(s)
Integer , intent(IN) :: x
integer :: t
t = abs(x)
s = 0
do
s = s + mod(t,10)
if( t < 10 ) exit
t = t/10
end do
End Function getDecimalismSum
End Program www_fcode_cn |
捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )
GMT+8, 2025-11-3 17:58