How to resolve the algorithm Ackermann function step by step in the PowerBASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Ackermann function step by step in the PowerBASIC programming language
Table of Contents
Problem Statement
The Ackermann function is a classic example of a recursive function, notable especially because it is not a primitive recursive function. It grows very quickly in value, as does the size of its call tree.
The Ackermann function is usually defined as follows:
Its arguments are never negative and it always terminates.
Write a function which returns the value of
A ( m , n )
{\displaystyle A(m,n)}
. Arbitrary precision is preferred (since the function grows so quickly), but not required.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Ackermann function step by step in the PowerBASIC programming language
Source code in the powerbasic programming language
FUNCTION PBMAIN () AS LONG
DIM m AS QUAD, n AS QUAD
m = ABS(VAL(INPUTBOX$("Enter a whole number.")))
n = ABS(VAL(INPUTBOX$("Enter another whole number.")))
MSGBOX STR$(Ackermann(m, n))
END FUNCTION
FUNCTION Ackermann (m AS QUAD, n AS QUAD) AS QUAD
IF 0 = m THEN
FUNCTION = n + 1
ELSEIF 0 = n THEN
FUNCTION = Ackermann(m - 1, 1)
ELSE ' m > 0; n > 0
FUNCTION = Ackermann(m - 1, Ackermann(m, n - 1))
END IF
END FUNCTION
You may also check:How to resolve the algorithm Five weekends step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Active object step by step in the Lua programming language
You may also check:How to resolve the algorithm Topswops step by step in the Factor programming language
You may also check:How to resolve the algorithm Pointers and references step by step in the Tcl programming language
You may also check:How to resolve the algorithm CUSIP step by step in the Nim programming language