How to resolve the algorithm Factorial step by step in the TUSCRIPT programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Factorial step by step in the TUSCRIPT 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 TUSCRIPT programming language
Source code in the tuscript programming language
$$ MODE TUSCRIPT
LOOP num=-1,12
IF (num==0,1) THEN
f=1
ELSEIF (num<0) THEN
PRINT num," is negative number"
CYCLE
ELSE
f=VALUE(num)
LOOP n=#num,2,-1
f=f*(n-1)
ENDLOOP
ENDIF
formatnum=CENTER(num,+2," ")
PRINT "factorial of ",formatnum," = ",f
ENDLOOP
You may also check:How to resolve the algorithm Inheritance/Multiple step by step in the Rust programming language
You may also check:How to resolve the algorithm Determine if a string is collapsible step by step in the Java programming language
You may also check:How to resolve the algorithm Call a function step by step in the F# programming language
You may also check:How to resolve the algorithm Jacobsthal numbers step by step in the Red programming language
You may also check:How to resolve the algorithm Write to Windows event log step by step in the Standard ML programming language