Assignment

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 20

1. Write a program using ASP.net to add two numbers.

UI Code

<%@ Page Language="C#" AutoEventWireup="true"


CodeBehind="AddTwoNumbers.aspx.cs" Inherits="Assignment.AddTwoNumbers" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtOne" runat="server"></asp:TextBox><br />
<asp:TextBox ID="txtTwo" runat="server"></asp:TextBox><br />
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click"
/><br />
<asp:Label ID="lblResult" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>

Code

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

namespace Assignment
{
public partial class AddTwoNumbers : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void btnAdd_Click(object sender, EventArgs e)


{
string txta, txtb, txtr;
double a, b, r;
txta = txtOne.Text;
txtb = txtTwo.Text;
a = Convert.ToDouble(txta);
b = Convert.ToDouble(txtb);
r = a + b;
txtr = r.ToString();
lblResult.Text = txtr;

}
}
}
2. Write a program using ASP.net to input a number and find the factorial.

UI Code

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Factorial.aspx.cs"


Inherits="Assignment.Factorial" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtNumber" runat="server"></asp:TextBox><br />
<asp:Button ID="btnAdd" runat="server" Text="Factorial"
OnClick="btnAdd_Click" /><br />
<asp:Label ID="lblResult" runat="server" Text="Factorial"></asp:Label>
</div>
</form>
</body>
</html>

Code

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

namespace Assignment
{
public partial class Factorial : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void btnAdd_Click(object sender, EventArgs e)


{
string txtn, txtr;
short a, i;
int f=1;
txtn = txtNumber.Text;
a = Convert.ToInt16(txtn);
if (a < 0)
{
lblResult.Text = "Factorial Not Possible";
}
else
{
for (i = 1; i <= a; i++)
{
f = f * i;
}
txtr = f.ToString();
lblResult.Text = "Factorial = " +txtr;
}

}
}
}
3. Write a program using ASP.net to input a number and check Number is Prime or Not.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PrimeNumber.aspx.cs"


Inherits="Assignment.PrimeNumber" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtNumber" runat="server"></asp:TextBox><br />
<asp:Button ID="btnPrime" runat="server" Text="Prime Number"
OnClick="btnPrime_Click" /><br />
<asp:Label ID="lblResult" runat="server" Text="Not Prime"></asp:Label>
</div>
</form>
</body>
</html>

Code

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

namespace Assignment
{
public partial class PrimeNumber : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void btnPrime_Click(object sender, EventArgs e)


{
string txtn, txtr;
short a, i;
bool flag = true;
txtn = txtNumber.Text;
a = Convert.ToInt16(txtn);
if (a < 1)
{
lblResult.Text = "Not Prime Number ";
}
else
{

for (i = 2; i <= a/2; i++)


{
if (a % i == 0)
{
flag = false;
}
}
if (flag)
{
lblResult.Text = a.ToString() + " is Prime Number ";
}
else
{
lblResult.Text = a.ToString() + " is Not Prime Number ";
}

}
}
}
}
4. Write a program using ASP.net to display prime numbers between two numbers.

<%@ Page Language="C#" AutoEventWireup="true"


CodeBehind="PrimeBetweenTwoNumbers.aspx.cs"
Inherits="Assignment.PrimeBetweenTwoNumbers" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtNumberStart" runat="server"></asp:TextBox><br />
<asp:TextBox ID="txtNumberEnd" runat="server"></asp:TextBox><br />
<asp:Button ID="btnPrime" runat="server" Text="Prime Number"
OnClick="btnPrime_Click" /><br />
<asp:ListBox ID="ListBox1" runat="server" Width="360px"></asp:ListBox>
</div>
</form>
</body>
</html>

Code

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

namespace Assignment
{
public partial class PrimeBetweenTwoNumbers : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void btnPrime_Click(object sender, EventArgs e)


{
string txtns, txtne;
short s,en, i,j;
bool flag;
txtns = txtNumberStart.Text;
txtne = txtNumberEnd.Text;
s = Convert.ToInt16(txtns);
en = Convert.ToInt16(txtne);
ListBox1.Items.Clear();
for (i = s; i <= en; i++)
{
flag = true;
for(j=2;j<=i/2; j++)
{
if (i % j == 0)
{
flag = false;
}
}
if (flag)
{
ListBox1.Items.Add(i.ToString());
}
}
}
}
}
5. Write a program using ASP.net to input a number and reverse it.

<%@ Page Language="C#" AutoEventWireup="true"


CodeBehind="ReverseNumber.aspx.cs" Inherits="Assignment.ReverseNumber" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtNumber" runat="server"></asp:TextBox><br />
<asp:Button ID="btnReverse" runat="server" Text="Reverse Number"
OnClick="btnReverse_Click" /><br />
<asp:Label ID="lblResult" runat="server" Text="0"></asp:Label>
</div>
</form>
</body>
</html>

Code

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

namespace Assignment
{
public partial class ReverseNumber : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void btnReverse_Click(object sender, EventArgs e)


{
string txtn;
int a, r,rev=0;
txtn = txtNumber.Text;
a = Convert.ToInt16(txtn);
while (a != 0)
{
r = a % 10;
rev = rev * 10 + r;
a = a / 10;
}
lblResult.Text = rev.ToString();
}
}
}
6. Write a program using ASP.net to reverse numbers between two numbers.

<%@ Page Language="C#" AutoEventWireup="true"


CodeBehind="ReverseNumberBetween.aspx.cs"
Inherits="Assignment.ReverseNumberBetween" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtNumberStart" runat="server"></asp:TextBox><br />
<asp:TextBox ID="txtNumberEnd" runat="server"></asp:TextBox><br />
<asp:Button ID="btnReverse" runat="server" Text="Reverse Number"
OnClick="btnReverse_Click" /><br />
<asp:ListBox ID="ListBox1" runat="server" Width="360px"></asp:ListBox>
</div>
</form>
</body>
</html>

Code

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

namespace Assignment
{
public partial class ReverseNumberBetween : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void btnReverse_Click(object sender, EventArgs e)


{
string txtn,txts;
int s,en, r, rev,a;
txtn = txtNumberStart.Text;
txts = txtNumberEnd.Text;
s = Convert.ToInt16(txtn);
en = Convert.ToInt16(txts);
ListBox1.Items.Clear();
for(int j = s; j <= en; j++)
{
a = j;
rev = 0;
while (a != 0)
{
r = a % 10;
rev = rev * 10 + r;
a = a / 10;
}
ListBox1.Items.Add(rev.ToString());
}
}
}
}
7. Write a program using ASP.net to armstrong numbers between two numbers.

<%@ Page Language="C#" AutoEventWireup="true"


CodeBehind="ArmstrongNumber.aspx.cs" Inherits="Assignment.ArmstrongNumber" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtNumberStart" runat="server"></asp:TextBox><br />
<asp:TextBox ID="txtNumberEnd" runat="server"></asp:TextBox><br />
<asp:Button ID="btnArm" runat="server" Text="Armstrong Number"
OnClick="btnArm_Click" /><br />
<asp:ListBox ID="ListBox1" runat="server" Width="360px"></asp:ListBox>
</div>
</form>
</body>
</html>

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

namespace Assignment
{
public partial class ArmstrongNumber : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void btnArm_Click(object sender, EventArgs e)


{

string txtn, txts;


int s, en, r, arm, a;
txtn = txtNumberStart.Text;
txts = txtNumberEnd.Text;
s = Convert.ToInt16(txtn);
en = Convert.ToInt16(txts);
ListBox1.Items.Clear();
for (int j = s; j <= en; j++)
{
a = j;
arm = 0;
while (a != 0)
{
r = a % 10;
arm = arm + r*r*r;
a = a / 10;
}
if (arm==j)
ListBox1.Items.Add(arm.ToString());
}
}
}
}
8. Write a program using ASP.net to check number is palindrome or not.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Palindrom.aspx.cs"


Inherits="Assignment.Palindrom" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtNumber" runat="server"></asp:TextBox><br />
<asp:Button ID="btnReverse" runat="server" Text="Palindrom Number"
OnClick="btnReverse_Click" /><br />
<asp:Label ID="lblResult" runat="server" Text="0"></asp:Label>
</div>
</form>
</body>
</html>

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

namespace Assignment
{
public partial class Palindrom : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void btnReverse_Click(object sender, EventArgs e)


{
string txtn;
int a, r, rev = 0,n;
txtn = txtNumber.Text;
a = Convert.ToInt16(txtn);
n = a;
while (a != 0)
{
r = a % 10;
rev = rev * 10 + r;
a = a / 10;
}
if (rev == n)
lblResult.Text = "Number is Palindrom";
else
lblResult.Text = "Number is not Palindrom";
}
}
}

9. Write a program using ASP.net to input number of rows and display.


1
12
123
1234

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Triangle1.aspx.cs"


Inherits="Assignment.Triangle1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Enter Number of
Rows"></asp:Label><br />
<asp:TextBox ID="txtNumber" runat="server" Text="0"></asp:TextBox><br />
<asp:Button ID="btnDraw" runat="server" Text="Draw"
OnClick="btnDraw_Click" /><br />
<asp:Label ID="lblResult" runat="server" ></asp:Label>
</div>
</form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Assignment
{
public partial class Triangle1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void btnDraw_Click(object sender, EventArgs e)


{
string txtn, st;
int a;
txtn = txtNumber.Text;
st = string.Empty;
a = Convert.ToInt16(txtn);
for(int i = 1; i <= a; i++)
{
for (int j = 1; j <= i; j++)
{
st = st + j.ToString() + " ";
}
st = st + "<br>";
}
lblResult.Text = st;
}
}
}
10. Write a program using ASP.net to input number of rows and display.
A
AB
ABC
ABCD

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Triangle1.aspx.cs"


Inherits="Assignment.Triangle1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Enter Number of
Rows"></asp:Label><br />
<asp:TextBox ID="txtNumber" runat="server" Text="0"></asp:TextBox><br />
<asp:Button ID="btnDraw" runat="server" Text="Draw"
OnClick="btnDraw_Click" /><br />
<asp:Label ID="lblResult" runat="server" ></asp:Label>
</div>
</form>
</body>
</html>

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

namespace Assignment
{
public partial class Triangle1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void btnDraw_Click(object sender, EventArgs e)


{
string txtn, st;
int a;
txtn = txtNumber.Text;
st = string.Empty;
a = Convert.ToInt16(txtn);
for(int i = 1; i <= a; i++)
{
for (int j = 1; j <= i; j++)
{
st = st + j.ToString() + " ";
}
st = st + "<br>";
}
lblResult.Text = st;
}
}
}

You might also like