How to Find the String is Palindrome or not in C#

This is the simple but trick programming exercise. The program will identify that is the string is palindrome or not. The palindrome is that which looks same from both sides e.g ACCA , DBBD. 

Source Code 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace pakindromeCS
{
class Program
{
static void Main(string[] args)
{
//Your code goes here
Console.WriteLine("Hello, world!");
String userEntered, palindrome = "";
Console.WriteLine("Enter some text to check palindrome");
userEntered = Console.ReadLine();
int stringSize = userEntered.Length;
for (int i = stringSize - 1; i >= 0; i--)
palindrome = palindrome + userEntered[i];

Console.WriteLine((userEntered == palindrome ? "palindrome." : "not a palindrome."));
userEntered = Console.ReadLine();
}
}
}


Output of the Program

How to Find the String is Palindrome or not in C#

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment