Fibonacci numbers in Dart
Example for versions
Dart 1.1.1
This example uses recursive definition of Fibonacci numbers. Note that the language requires explicit conversion from int to String.
int fibonacci(int n) => n <= 2 ? 1 : fibonacci(n - 2) + fibonacci (n - 1);
main() {
String output = "";
for (int i = 1; i <= 16; ++i) {
output += fibonacci(i).toString() + ", ";
}
print(output + "...");
}
Comments
]]>View the discussion thread.
blog comments powered by Disqus
]]>