Академический Документы
Профессиональный Документы
Культура Документы
c-sharpcorner.com
Google detected you're on a slow connection and optimised this page to use 80% less data.
Optimized 11 minutes ago
View original Refresh
BLOG
Program to Check Whether a String Palindrome is or not
By Priyanka Jain on Nov 19, 2013
It contains a program to reverse a string and to check whether a Entered string is palindrome or not.
AngularJS JumpStart with Dan Wahlin
It contains a program to reverse a string and to check whether a Entered string is palindrome or not.
using System;
namespace palindrome
{
class Program
{
static void Main(string[] args)
{
string s,revs="";
Console.WriteLine(" Enter string");
s = Console.ReadLine();
for (int i = s.Length-1; i >=0; i--) //String Reverse
{
revs += s[i].ToString();
}
if (revs == s) // Checking whether string is palindrome or not
{
Console.WriteLine("String is Palindrome \n Entered String Was {0} and reverse string is {1}", s, revs);
}
else
{
Console.WriteLine("String is not Palindrome \n Entered String Was {0} and reverse string is {1}", s, revs);
}
Console.ReadKey();
}
}
}
873 358.7k
Rank Read
Bronze
Member
COMMENTS (7)
Here is more efficient code for checking palindrome string public static bool palindrome(string str) { if (str.Length
< 2) return false; for (int i = 0, len = str.Length - 1; i < str.Length / 2; i , len--) { if (str[i] == '.') i ;// This code is to ignore
. if (str[len] == '.') len--;//this code is to ignore . if (str[i] != str[len]) return false; } return true; }
NA 0 0
Gurunath Navale
Apr 30, 2014 0 0 Post Reply
It works only for Case sensitive string.Like according to above Program 'Malayalam' is Not Palindrome while
'malayalam' is Palindrome.
Can any one help me to make a program in c# to find out number of palindrome substring in a string
1264 51 3.4k
Ashvani chaudhary
Jul 01, 2015 0 0 Post Reply
Here is my code without using any for loops:using System;public class Test{ public static void Main() { string
s=Console.ReadLine(); char[] rev=s.ToCharArray(); Array.Reverse(rev); string revs=new string(rev);
if(s.Equals(revs)) Console.WriteLine("Palindrome"); else Console.WriteLine("Not Palindrome"); } }
phaneendra chakravaram
nice dude...thank u Jan 10, 2016
NA 0 0 1247 68 2.6k
Roshan Halwai
Sep 21, 2015 0 1 Post Reply 0
phaneendra chakravaram
Thank u Jan 10, 2016
1247 68 2.6k
0 0 Post Reply
string strVal = "Malayalam".ToLower(); char[] alpha = strVal.ToCharArray(); int i = 0; int strlen = strVal.Length; for (
i = 0; i <= alpha.Length-1; i++) {string FirstVal = alpha.GetValue(i).ToString(); string LastVal =
alpha.GetValue(strlen-1).ToString(); if (FirstVal == LastVal){strlen = strlen - 1;} else {Console.WriteLine("this is Not
pallindrome");return;} }
1314 1 0
Abhay Kumar
Jan 18, 2016 0 0 Post Reply
Contact Us Privacy Policy Terms & Conditions About Us