To download NI software, including the products shown below, visit ni.com/downloads.
Overview
This example uses the new drag and drop recursion interface to calculate the Factorial of a given number N
Requirements
LabVIEW Base Development System 2012 or compatible
Steps to Implement or Execute Code
Description
This example uses the new drag and drop recursion interface to calculate the Factorial of a given number N. This VI uses a standard algorithm that can be found on wikipedia.
Additional Information or References
VI Block Diagram
Description-Separate-2
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
it doesn't work for number higher than 5
I uploaded a new version that uses U32 integer data types, this will allow it to work for bigger numbers. The previous version was limited because it was the i8 data type (-128 to 127)
0! is not handled correctly. 0! is defined as 1. See various links:
http://mathforum.org/library/drmath/view/57905.html
http://wiki.answers.com/Q/Why_is_zero_factorial_equal_to_one
http://en.wikipedia.org/wiki/Factorial#Definition
A simple way to fix your VI:
1. Change the >1 to >0.
2. In the TRUE case, hard-wire a 1 to the output.