How to print Palindrom String in C#

Shubham
Posted by Shubham under C# category on | Points: 40 | Views : 1815
using System;
class test
{
public static void Main()
{
Console.BackgroundColor = ConsoleColor.Blue;
string name = Console.ReadLine();
int f = name.Length - 1;
int j = 0;
int flag = 0;
while (j <f)
{
if (name[j] == name[f])
{
flag = 1;
}
else
{
flag = 0;
}
j++;
f--;
}
if (flag == 1)
{
Console.WriteLine("Palimdrom");
}
else
{
Console.WriteLine("Not Palimdrom");

}
Console.ReadLine();
}
}

Comments or Responses

Posted by: Omniitstudent on: 2/18/2012 Level:Starter | Status: [Member] | Points: 10
using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
//A palindrome is a word, phrase, number, or other sequence of units that can be read the same way in either direction.
namespace ConsoleApplication26
{
class Program
{
static void Main(string[] args)
{
string sInp=Console.ReadLine();

int flag = 1;
string s = string.Empty;
for (int i=sInp.Length-1; i>=0; i--)
{
s += sInp[i];

}

if (s==sInp)
{
Console.WriteLine("Entered value is palindrome");
}
else
{
Console.WriteLine("Entered value is not palindrome");
}
Console.ReadLine();
}
}
}
=================input- madam
output- Entered value is not palindrome


==Crazy Code........

Posted by: T.Saravanan on: 2/20/2012 Level:Silver | Status: [Member] [MVP] | Points: 10
Hi All,

@Shubham Kumar, kindly post your code inside the code tag.


@OmPrakash, don't declare variable as 'i' in our DNF. Because in our DNF its consider as 'Italic' format. Kindly change those in your code.

Login to post response