Summing up digits of provided number

Rem Sum of digits of Number Example: Sum of digits of 254 is 11
CLS
INPUT "Number=";n
a=n
WHILE a<>0
  r=a MOD 10
  s=s+r
  a=int(a/10)
WEND
PRINT "Sum of  digits of ";a; " is ";s
END

2 comments: