How to resolve the algorithm Sum digits of an integer step by step in the Ursa 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 Ursa 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 Ursa programming language

Source code in the ursa programming language

def sumDigits (string val, int base)
	decl int ret
	for (decl int i) (< i (size val)) (inc i)
		set ret (+ ret (int val base))
	end for
	return ret
end sumDigits

out (sumDigits "1" 10) endl console
out (sumDigits "1234" 10) endl console
out (sumDigits "fe" 16) endl console
out (sumDigits "f0e" 16) endl console

  

You may also check:How to resolve the algorithm Langton's ant step by step in the Furor programming language
You may also check:How to resolve the algorithm Boolean values step by step in the Trith programming language
You may also check:How to resolve the algorithm Idoneal numbers step by step in the Go programming language
You may also check:How to resolve the algorithm Random Latin squares step by step in the Pascal programming language
You may also check:How to resolve the algorithm Kronecker product step by step in the Java programming language