Factorial in Dart
Example for versions
Dart 1.1.1
This example uses recursive factorial definition. int
datatype is an integer of arbitrary size.
int factorial(int n) => n == 0 ? 1 : n * factorial(n - 1);
main() {
for (int i = 0; i <= 16; ++i) {
print('$i! = ${factorial(i)}');
}
}
Comments
]]>blog comments powered by Disqus
]]>