Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default2.aspx.cs"
Inherits="TemperatureConversion.Default2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Enter a : <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div> <p>
Enter b : <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</p>
Enter c :<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<p>
<asp:Button ID="Button1" runat="server" Text="Result" OnClick="Button1_Click" />
</p> <p>
<asp:Label ID="Label3" runat="server" Text=""></asp:Label>
</p>
<p>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
</p>
</form>
</body>
</html>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace quadraticEquation
{
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
demo();
}
public void demo()
{
double a, b, c, r1, r2, x;
double det;
a = Convert.ToInt32(TextBox1.Text);
b = Convert.ToInt32(TextBox2.Text);
c = Convert.ToInt32(TextBox3.Text);
det = (b * b) - (4 * a * c);
if (det >0)
{
x = Math.Sqrt(det);
r1 = (-b + x) / (2 * a);
r2 = (-b - x) / (2 * a);
Label3.Text = "There are two roots ::";
Label1.Text = r1.ToString();
Label2.Text = r2.ToString();
}
else if(det==0)
{
x = Math.Sqrt(det);
r1 = (-b + x) / (2 * a);
Label1.Text = "There is only one root ::";
Label2.Text = r1.ToString();
}
else
{
Label1.Text = "There is no root !!!";
}
}
}
}
0 Comments