primerange.aspx.cs
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="primerange.aspx.cs" Inherits="our_program.primerange" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<center><h1>prime in a range</h1></center>
</head>
<body>
<form id="form1" runat="server">
<center>
<div>
<asp:TextBox ID="txt" runat="server"></asp:TextBox>
<br />
<br />
<asp:TextBox ID="txt1" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="btn" runat="server" Text="Button" onclick="btn_Click" />
<br />
<br />
<asp:Label ID="lbl" runat="server" Text="result are shown here"></asp:Label>
</div>
</center>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<center><h1>prime in a range</h1></center>
</head>
<body>
<form id="form1" runat="server">
<center>
<div>
<asp:TextBox ID="txt" runat="server"></asp:TextBox>
<br />
<br />
<asp:TextBox ID="txt1" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="btn" runat="server" Text="Button" onclick="btn_Click" />
<br />
<br />
<asp:Label ID="lbl" runat="server" Text="result are shown here"></asp:Label>
</div>
</center>
</form>
</body>
</html>
primerange.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace our_program
{
public partial class primerange : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_Click(object sender, EventArgs e)
{
int l = Convert.ToInt16(txt.Text);
int u = Convert.ToInt16(txt1.Text);
string output = "";
int a = l + 1;
for (int i = a; i < u; i++)
{
int f = 0;
for (int j = 2; j < i; j++)
{
if (i % j == 0)
{
f = 1;
break;
}
}
if (f == 0)
{
output = output + "<br>" + i;
}
}
lbl.Text = "prime numbers b/w " + l + " and " + u + " are " + output;
}
}
}
No comments:
Post a Comment