I need to make a method that returns the nth integer in the fibonacci series, the code that I wrote (edited) did not work, could anyone guide me in my for loop section. I need to use a webform and return the fibonacci series to a specific point.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
{
public partial class Default : System.Web.UI.Page
{
int i, temp;
public void Page_Load(object sender, EventArgs e)
{
}
public int Fibonacci(int x)
{
if (x == 0)
{
return 1;
}
if (x == 1)
{
return 1;
}
else
{
return (Fibonacci(x - 2) + Fibonacci(x - 1));
}
}
public void btSubmit_Click(object sender, EventArgs e)
{
// getting input from user
int num = Convert.ToInt32(txtInput.Text);
// logic for fibonacci series
for (i = 0; i < num; i++)
{
lblResult.Text = Fibonacci(i).ToString();
}
}
}
}