PROGRAM TO FIND THE SUM OF N NATURAL NUMBERS

DEFAULT.ASPX FILE:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        &nbsp; &nbsp; <asp:Label ID="Label3"
            runat="server" Text="RESULT :" Width="130px"></asp:Label>&nbsp;
        <asp:Label ID="Label1" runat="server" Width="153px"></asp:Label><br />
        &nbsp; &nbsp;&nbsp;<br />
        &nbsp;<asp:Label ID="Label2" runat="server" Text="Enter the limit to sum"
            Width="157px"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>&nbsp; &nbsp;&nbsp;&nbsp;<br />
        <br />
        &nbsp;<asp:Button ID="Button1" runat="server" Text="USE WHILE LOOP" Width="138px" /><br />
        <br />
        <br />
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br />
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
    </div>
    </form>
</body>
</html>

DEFAULT.ASPX.VB FILE:

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sum = 0
        Dim c, i As Integer
        c = CInt(TextBox1.Text)
        While (i <= c)
            sum = sum + i
            i = i + 1
        End While
        Label1.Text = sum
    End Sub
End Class


No comments:

Post a Comment