0% found this document useful (0 votes)
18 views

Loop Eventargs: "Number Should Be Greater Than 1"

The document contains code for a web page that calculates and displays Fibonacci numbers. It includes a text box where a number can be entered. When a button is clicked, it converts the text to an integer and uses a for loop to calculate the Fibonacci sequence up to that number. It displays each term on a new line in a label on the page. Error handling is included to display a message if 0 or a negative number is entered.

Uploaded by

arshee
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Loop Eventargs: "Number Should Be Greater Than 1"

The document contains code for a web page that calculates and displays Fibonacci numbers. It includes a text box where a number can be entered. When a button is clicked, it converts the text to an integer and uses a for loop to calculate the Fibonacci sequence up to that number. It displays each term on a new line in a label on the page. Error handling is included to display a message if 0 or a negative number is entered.

Uploaded by

arshee
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

using System;

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class loop : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
string str;
str = TextBox1.Text;
int n = Convert.ToInt16(str);
int t1 = 0, t2 = 1, nextterm = 0;
string result;
if (n == 0)
{
Label1.Text = "Number should be greater than 1";
}
else
{
Label1.Text = Convert.ToString(0) + Environment.NewLine;
for (int i = 2; i <= n; i++)
{
t1 = t2;
t2 = nextterm;
nextterm = t1 + t2;
result = Convert.ToString(nextterm);
Label1.Text += result + Environment.NewLine;
}
}

}
}

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="loop.aspx.cs" Inherits="loop" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
<asp:TextBox ID="TextBox1" runat="server" TextMode="Number"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="fibonacci"
/>
<p>
<asp:Label ID="Label1" runat="server"></asp:Label>
</p>
</form>
</body>
</html>
OUTPUT:

You might also like