How to resolve the algorithm Factorial step by step in the CLU programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Factorial step by step in the CLU 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 CLU programming language

Source code in the clu programming language

factorial = proc (n: int) returns (int) signals (negative)
    if n<0 then signal negative
    elseif n=0 then return(1)
    else return(n * factorial(n-1))
    end
end factorial

start_up = proc ()
    po: stream := stream$primary_output()
    
    for i: int in int$from_to(0, 10) do
        fac: int := factorial(i)
        stream$putl(po, int$unparse(i) || "! = " || int$unparse(fac))
    end
end start_up

  

You may also check:How to resolve the algorithm Sudoku step by step in the BCPL programming language
You may also check:How to resolve the algorithm Numerical integration step by step in the MATLAB / Octave programming language
You may also check:How to resolve the algorithm Execute Computer/Zero step by step in the Python programming language
You may also check:How to resolve the algorithm Sorting algorithms/Stooge sort step by step in the Maple programming language
You may also check:How to resolve the algorithm FizzBuzz step by step in the PHL programming language