| 本帖最后由 楚香饭 于 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 |