photo

Farhath Surayya


Last seen: 4 years ago Active since 2020

Followers: 0   Following: 0

Statistics

  • First Answer

View badges

Feeds

View by

Answered
I want to write a recursive Function that can calculate the sum of all the digit. If the input is 12345 then the answer will be 1+2+3+4+5 , without using string2num and loop.
function output= digit_sum(n) if n<10 output=fix(n); end if n>0 output=output+digit_sum(n*0.1); end end

4 years ago | 0