How to generate Fibonacci Triangle in C# ?

0 votes
111 views
Rahul Ahuja asked 12-Sep-2018 in programming by Rahul Ahuja

1 Answer

0 votes
Sanat Shukla answered 12-Sep-2018 by Sanat Shukla

Fibonacci Triangle

How to generate Fibonacci Triangle in C# ?

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Fibonacci_Triangle
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 0, b = 1, i, c, n, j;
            Console.Write("Enter the limit: ");
            n = int.Parse(Console.ReadLine());
            for (i = 1; i <= n; i++)
            {
                a = 0;
                b = 1;
                Console.Write(b + "\t");
                for (j = 1; j < i; j++)
                {
                    c = a + b;
                    Console.Write(c + "\t");
                    a = b;
                    b = c;
                }
                Console.Write("\n");
            }
        }
    }
}