Factorial in bc
Example for versions
bc 1.06
This example uses recursive factorial definition.
define factorial(n) {
if (n == 0) return(1);
return(n * factorial(n - 1));
}
for (n = 0; n <= 16; n++) {
print n; "! = "; factorial(n);
}
Comments
]]>blog comments powered by Disqus
]]>