using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Fibonacciseries
{
int prev = 0;
int next = 1;
public void fibonacci(int n)
{
for (int i = 0; i < n; i++)
{
int sum = prev + next;
prev = next;
next = sum;
Console.WriteLine(sum);
}
}
static void Main(string[] args)
{
Fibonacciseries ob = new Fibonacciseries();
Console.WriteLine("Please enter the length of the series");
ob.fibonacci(Convert.ToInt32(Console.ReadLine()));
Console.ReadKey();
}
}
}
No comments:
Post a Comment