You are here: Start » Tutorial Exercises » ADVANCED: Factorial

ADVANCED: Factorial

Aim:

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

The function argument should be provided as an Integer.

Input:

A single integer for which the factorial value should be computed.

Output:

The factorial value of the input value.

Hints:

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

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

Labeling connections is explained in this article.

Solution (FIS)

  1. Add a new Global Parameter of Integer type. Name it N and set its initial value to 5.

  2. Add a new register regFactorial of type Long. To do so, right-click on the Main macrofilter in the Project Explorer and select Add Macrofilter Register option:

    Set its default value to 1 as shown in the image below.

    Label the prevFactorial register as Factorial afterwards.

  3. Add the filter EnumerateIntegers to the ACQUIRE section and set inStart to 1. Label the output as Value.

  4. Connect your Global Parameter N**** with inCount.

  5. Add a new Formula in the PROCESS section and create a NextFactorial output of Long type:

    NextFactorial = Value * Factorial

  6. Connect the NextFactorial formula's output with the register's output: nextFactorial .

Macrofilter Factorial computes a factorial value to using its registers.