using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Palindromeprogram
{
class Program
{
static void Main(string[] args)
{
string str = string.Empty;
Console.WriteLine("Enter a String");
string s = Console.ReadLine();
int i = s.Length;
//we can get the Length of string by using Length Property
for (int j = i - 1; j >= 0; j--)
{
str = str + s[j];
}
if (str == s)
{
Console.WriteLine(s + " is palindrome");
}
else
{
Console.WriteLine(s + " is not a palindeome");
}
Console.WriteLine(str);
Console.ReadLine();
}
}
}
Output:
1. Enter a String "allagalla"
allagalla is palindrome
allagalla
2. Enter a String "India"
India is not a Palindrome
India
3. Enter a String "madam"
madam is a Palindrome
madam
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Palindromeprogram
{
class Program
{
static void Main(string[] args)
{
string str = string.Empty;
Console.WriteLine("Enter a String");
string s = Console.ReadLine();
int i = s.Length;
//we can get the Length of string by using Length Property
for (int j = i - 1; j >= 0; j--)
{
str = str + s[j];
}
if (str == s)
{
Console.WriteLine(s + " is palindrome");
}
else
{
Console.WriteLine(s + " is not a palindeome");
}
Console.WriteLine(str);
Console.ReadLine();
}
}
}
Output:
1. Enter a String "allagalla"
allagalla is palindrome
allagalla
2. Enter a String "India"
India is not a Palindrome
India
3. Enter a String "madam"
madam is a Palindrome
madam
Easy and great code thnx for sharing
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHere is my code to check palindrome string
ReplyDeletepublic 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;
}
Print 1 to n Prime numbers - Simple code for you to crack Interview
ReplyDeletePrint 1 to n Prime numbers - Simple code for you to crack Interview