Post

# Triangle With A Fibonacci Series In C#

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#.

1. namespace ConsoleApplication1 {
2.     class Program {
3.         static void Main(string[] args) {
4.             int a = 0, b = 1, c = 1, total;
5.             Console.WriteLine("Enter How many numbers you want to given ? ");
7.             Console.Write("\n");
8.             for (int i = 1; i <= total; i++) {
9.                 for (int j = 1; j <= i; j++) {
10.                     if (i == 1 && j == 1) {
11.                         Console.Write(" 0");
12.                         continue;
13.                     }
14.                     Console.Write(" {0}", c);
15.                     c = a + b;
16.                     a = b;
17.                     b = c;
18.                 }
19.                 Console.Write("\n");
20.             }