Concept of Fibonacci Series
The Fibonacci series is a sequence of numbers where:
Each number is the sum of the two preceding numbers.
Mathematically
F(0) = 0
F(1) = 1
F(n) = F(n - 1) + F(n - 2)
Example Output0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
What is Recursion in Fibonacci?
Recursion means a function calls itself.
In this case, the Fibonacci function calls itself to calculate previous numbers.
Recursive Formula
Fibonacci(n) = Fibonacci(n - 1) + Fibonacci(n - 2)
Real-Time Example: Fibonacci in C# WebForms
Step 1: Design Page – RecursiveFibonacci.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RecursiveFibonacci.aspx.cs" Inherits="RecursiveFibonacci" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Recursive Fibonacci using C# WebForms</title>
<style>
body {
font-family: Arial;
background-color: #f4f7fc;
margin: 50px;
}
.container {
width: 500px;
margin: auto;
background: #fff;
border-radius: 10px;
box-shadow: 0 0 10px #ccc;
padding: 25px;
}
h2 {
text-align: center;
color: #1A2A80;
}
.form-control {
width: 100%;
padding: 8px;
margin-top: 10px;
}
.btn {
background-color: #7A85C1;
color: white;
border: none;
padding: 10px;
border-radius: 5px;
cursor: pointer;
width: 100%;
margin-top: 10px;
}
.btn:hover {
background-color: #5b68a1;
}
.result {
margin-top: 20px;
font-weight: bold;
color: #333;
text-align: center;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="container">
<h2>Recursive Fibonacci Function</h2>
<asp:Label ID="lblInput" runat="server" Text="Enter Number of Terms:"></asp:Label><br />
<asp:TextBox ID="txtNumber" runat="server" CssClass="form-control" placeholder="Example: 8"></asp:TextBox><br />
<asp:Button ID="btnGenerate" runat="server" Text="Generate Fibonacci Series" CssClass="btn" OnClick="btnGenerate_Click" /><br />
<asp:Label ID="lblResult" runat="server" CssClass="result"></asp:Label>
</div>
</form>
</body>
</html>

Join the conversation! Your thoughts help the community grow.