How to resolve the algorithm Sum digits of an integer step by step in the Oforth programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Sum digits of an integer step by step in the Oforth programming language

Table of Contents

Problem Statement

Take a   Natural Number   in a given base and return the sum of its digits:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Sum digits of an integer step by step in the Oforth programming language

Source code in the oforth programming language

: sumDigits(n, base)  0 while( n ) [ n base /mod ->n + ] ;

sumDigits(1, 10) println
sumDigits(1234, 10) println
sumDigits(0xfe, 16) println
sumDigits(0xf0e, 16) println

  

You may also check:How to resolve the algorithm Zhang-Suen thinning algorithm step by step in the J programming language
You may also check:How to resolve the algorithm Non-decimal radices/Output step by step in the Go programming language
You may also check:How to resolve the algorithm N-queens problem step by step in the AppleScript programming language
You may also check:How to resolve the algorithm Long multiplication step by step in the Vedit macro language programming language
You may also check:How to resolve the algorithm Benford's law step by step in the Erlang programming language