Factorial (Recursive)
GlobalRecursion
Created by pattakorn.k on Oct 1, 2026
Pseudocode
// PSC:1.0 Factorial
// Description: Computes n! with a function that calls itself
FUNCTION factorial(n)
IF n <= 1
RETURN 1
END IF
LET smaller = CALL factorial(n - 1)
RETURN n * smaller
END FUNCTION
BEGIN Factorial
INPUT "Enter a whole number: " n
IF n < 0
OUTPUT "Factorial is not defined for negative numbers"
ELSE
LET result = CALL factorial(n)
OUTPUT n "! = " result
END IF
ENDInteractive Preview
Generating flowchart…