In fibonacci series, next number is the sum of previous two numbers for example 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 etc. The first two numbers of fibonacci series are 0 and 1.
In this example, You’ll see the fibonacci series program in C# without using recursion.
Source Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp9 { class Program { static void Main() { int n, a = 0, b = 1, c, i; Console.Write("Enter the number of terms : "); n = Int32.Parse(Console.ReadLine()); for (i = 0; i < n; i++) { if (i <= 1) c = i; else { c = a + b; a = b; b = c; } Console.Write(c+" "); } Console.ReadKey(); } } } |
Output: