You are here: Start » Tutorial Exercises » ADVANCED: Factorial (factorial)

ADVANCED: Factorial (factorial)

Aim

Create a macrofilter which computes a factorial for a given value.

The function argument should be provided as Integer.

Input

Single integer, for which factorial value should be computed.

Output

Factorial value of the input value.

Hints

This exercise should be solved using macrofilter's registers. All computed steps should be accumulated in a single macrofilter register.

Create the Task macrofilter which computes factorial value using the internal EnumerateIntegers filter.

Solution (AVS)

  1. Create a new Task macrofilter and name it Factorial.

  2. Create an input inN of type Integer.

  3. Enter to the Factorial macrofilter and add a new register regFactorial of type Integer. Set its default value to 1 as on the image below.

    Configuring a macrofilter's register:

  4. Add filter EnumerateIntegers to macrofilter Factorial and set inStart to 1.

  5. Connect inN to inCount of macrofilter EnumerateIntegers.

  6. Add filter MultiplyIntegers to macrofilter and connect to it outValue to the first output.

  7. To second output of MultiplyIntegers connect the value from previous iteration of the macrofilter prevFactorial.

  8. Connect output of MultiplyIntegers to the next value of register nextFactorial.

  9. Create a new macrofilter output outValue of type Integer and connect to it outProduct of filter MultiplyIntegers.

  10. Set a default output value of the outValue output to 1. This value will be set on the output when any iteration of the internal loop was performed.

Macrofilter Factorial computes a factorial value to using its registers.