In the case of a Fibonacci Series, the next number is the sum of previous two numbers. For example 0, 1, 1, 2, 3, 5, 8, 13, 21 etc. The first two numbers of Fibonacci Series are 0 and 1.
Let's see the Fibonacci Series program in C#.
- namespace ConsoleApplication1 {
- class Program {
- static void Main(string[] args) {
- int a = 0, b = 1, c = 1, total;
- Console.WriteLine("Enter How many numbers you want to given ? ");
- total = Convert.ToInt32(Console.ReadLine());
- Console.Write("\n");
- for (int i = 1; i <= total; i++) {
- for (int j = 1; j <= i; j++) {
- if (i == 1 && j == 1) {
- Console.Write(" 0");
- continue;
- }
- Console.Write(" {0}", c);
- c = a + b;
- a = b;
- b = c;
- }
- Console.Write("\n");
- }
- Console.ReadLine();
- }
- }
- }
Output