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)
-
Add a new Global Parameter of Integer type. Name it N and set its initial value to 5.
-
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.
-
Add the filter EnumerateIntegers to the ACQUIRE section and set inStart to 1. Label the output as Value.
-
Connect your Global Parameter N**** with inCount.
-
Add a new Formula in the PROCESS section and create a NextFactorial output of Long type:
NextFactorial = Value * Factorial
-
Connect the NextFactorial formula's output with the register's output: nextFactorial .