Fibonacci Series Programme in Dart Flutter

 import 'dart:io';


/// 1st Method for Fibonacci Series
// void main()
// {
// print("Please Enter the no. of terms of Fibonacci sequence to print : ");
// var terms = int.parse(stdin.readLineSync().toString());
//
// var no1 = 0;
// var no2 = 1;
//
// print(no1);
// print(no2);
//
// for(int i = 3; i <= terms; i++)
// {
// int sum = no1 + no2;
// print(sum);
// no1 = no2;
// no2 = sum;
// }
// }

/// 2nd Method for Fibonacci Series
void main() {
print("Please Enter the no. of terms of Fibonacci sequence to print : ");
var terms = int.parse(stdin.readLineSync().toString());

List<int> fiboSeq = [0, 1];

while (fiboSeq.length < terms) {
int sum = fiboSeq[fiboSeq.length - 1] + fiboSeq[fiboSeq.length - 2];
fiboSeq.add(sum);
}
print(fiboSeq);
}
Please Enter the no. of terms of Fibonacci sequence to print : 
5
[0, 1, 1, 2, 3]
Please Enter the no. of terms of Fibonacci sequence to print : 
10
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
Please Enter the no. of terms of Fibonacci sequence to print : 
15
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377]
Please Enter the no. of terms of Fibonacci sequence to print : 
20
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181]
Please Enter the no. of terms of Fibonacci sequence to print : 
17
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987]
Please Enter the no. of terms of Fibonacci sequence to print : 
12
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
Please Enter the no. of terms of Fibonacci sequence to print : 
8
[0, 1, 1, 2, 3, 5, 8, 13]
Please Enter the no. of terms of Fibonacci sequence to print : 
14
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233]

Comments

Popular posts from this blog

Second GET API Calling with Bloc simple Example in Flutter

Stack Container Scrollable Card widget UI with Custom Widget

Pagination with Bloc Pattern in Flutter