Fibonacci sequence in C#

Fibonacci sequence in C#

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

namespace value
{
    class Program
    {
        static void Main(string[] args)
        {
            int n,i,t=0,q=1,tot=0;

            Console.WriteLine("Enter the number.");
            n = int.Parse(Console.ReadLine());

            Console.WriteLine("fibonacci series {0}",t);
            Console.WriteLine("fibonacci series  {0}",q);
          

            for (i=3; i<=n;++i)
                {
                tot = t + q;
                t = q;
                q = tot;
                Console.WriteLine("Fibonacci number \n {0} ",tot);
                }
          
            Console.ReadLine();
        }
    }
}
output:- 0 1 1 2 3 5 8 13 21 34

Share this

1 comments:

comments
30 August 2016 at 03:50 delete

This blog is very helpful to beginners

Reply
avatar

:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
:>)
(o)
:p
:-?
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
$-)
(y)
(f)
x-)
(k)
(h)
cheer