Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR DART

fibonacci numbers in dart

import 'dart:io';

void main() {
  stdout.write("How many Fibonacci numbers do you want? ");
  int chosenNumber = int.parse(stdin.readLineSync());

  List<int> result = fibonacciNumbers(chosenNumber);
  print(result);
}

// Function to calulcate the Fibonacci numbers
List<int> fibonacciNumbers(int chosenNumber) {
  List<int> fibList = [1, 1];

  for (var i = 0; i < chosenNumber; i++) {
    fibList.add(fibList[i] + fibList[i + 1]);
  }
  return fibList;
}
Source by hackmd.io #
 
PREVIOUS NEXT
Tagged: #fibonacci #numbers #dart
ADD COMMENT
Topic
Name
5+9 =