Thursday 4 August 2016

write a program to check palindrom or not in asp.net

palindrom.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="palindrom.aspx.cs" Inherits="our_program.palindrom" %>

<!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>Palindrom</title>
    <center><h1>Palindrom</h1></center>
</head>
<body>
    <form id="form1" runat="server">
    <center>
    <div>
    <asp:TextBox ID="txt" runat="server"></asp:TextBox>
    <br />
    <br />
    <asp:Label ID="lbl" runat="server" Text="palindrom or not"></asp:Label>
    <br />
    <br />
    <asp:Button ID="btn" runat="server"  Text="submit" onclick="btn_Click"/>
    </div>
    </center>
    </form>
</body>
</html>

palindrom.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 palindrom : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btn_Click(object sender, EventArgs e)
        {
            string a = txt.Text;
            string output = "";
            int v = a.Length - 1;
            char[] array = a.ToCharArray();
            for (int i = v; i >= 0;i-- )
            {
                output = output + array[i].ToString();
            }
            if (output == a)
            {
                lbl.Text = a + "  this is palindrom";
            }
            else
            {
                lbl.Text = a + "this is not palindrom";
            }

        }
    }
}

No comments:

Post a Comment