Factorial in D Language -
i have started d , trying write simple factorial program in d. there vectors of c++ in d? wanted use vectors create dynamic function compute factorial.
why don't use std.bigint? - it's optimized arbitrary-precision numerics. ulong
(2^64
) can compute factorial until 20 , use-case inline-table might make more sense. here's example bigint
:
import std.bigint : bigint; bigint factorial(int n) { auto b = bigint(1); foreach (i; 1..n + 1) b *= i; return b; } void main () { import std.stdio : writeln; factorial(10).writeln; // 3628800 factorial(100).writeln; // 9.33 * 10^157 }
if want learn more dynamic arrays, maybe dlang tour pages arrays or slices might you?
Comments
Post a Comment