How to resolve the algorithm Factorial step by step in the zkl programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Factorial step by step in the zkl programming language
Table of Contents
Problem Statement
Write a function to return the factorial of a number. Solutions can be iterative or recursive. Support for trapping negative n errors is optional.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Factorial step by step in the zkl programming language
Source code in the zkl programming language
fcn fact(n){[2..n].reduce('*,1)}
fcn factTail(n,N=1) { // tail recursion
if (n == 0) return(N);
return(self.fcn(n-1,n*N));
}
fact(6).println();
var BN=Import("zklBigNum");
factTail(BN(42)) : "%,d".fmt(_).println(); // built in as BN(42).factorial()
You may also check:How to resolve the algorithm Euler method step by step in the Tcl programming language
You may also check:How to resolve the algorithm GUI component interaction step by step in the C programming language
You may also check:How to resolve the algorithm Old lady swallowed a fly step by step in the Phix programming language
You may also check:How to resolve the algorithm Introspection step by step in the Python programming language
You may also check:How to resolve the algorithm Sorting algorithms/Selection sort step by step in the D programming language