How genrate the Fibonacci Series upto a Limit and display it in the ListView Control

Er.deepakdalal
Posted by Er.deepakdalal under C# category on | Views : 4221
using System;
using System.Windows.Forms;

namespace Fibonacci_Series
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void gSeries_Click(object sender, EventArgs e)
{
if(Limit.Text.Length>0)
{
Genrate_Fibonacci_Series(Convert.ToInt32(Limit.Text));
}
else
{
MessageBox.Show("Please enter the limit before genrating the series","Warning",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}

public void Genrate_Fibonacci_Series(int Limit)
{
int Pre_Num = -1;
int Nxt_Num = 1;
LV.Items.Clear();
for (int i = 0; i <= Limit; i++)
{
int Sum = Pre_Num + Nxt_Num;
Pre_Num = Nxt_Num;
Nxt_Num = Sum;
LV.Items.Add(Sum.ToString());
}

}

}
}

Comments or Responses

Login to post response