Factorial in gnuplot
Example for versions
gnuplot 4.2.2
This example consists of two files: factorial.gp and run.gp to emulate loop through use of load
, reread
and if
.
Built-in factorial operator !
is used.
Since return of !
operator has type real, function gprintf
is used to remove trailing zeros after decimal point and decimal point itself.
### factorial.gp
print a, '! = ', gprintf("%.0f", a!)
a = a + 1
if (a <= 16) reread
### run.gp
#!/usr/bin/env gnuplot
a = 0
load "factorial.gp"
Comments
]]>blog comments powered by Disqus
]]>