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();
}
}
}
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
1 comments:
commentsThis blog is very helpful to beginners
Reply