2
Answers

Write a program to check any number or string is palindrome

Ravi Yadav

Ravi Yadav

8y
482
1
class Ravishanakr
{
static void Main(string[] args)
{
Ravishanakr _Ravi = new Ravishanakr();
Console.WriteLine("Enter string by keyboard");
string _OldString = Console.ReadLine();
_Ravi._PlandromString(_OldString);
Console.WriteLine("Enter number by keyboard");
long _Number = Convert.ToInt64(Console.ReadLine());
_Ravi._PlandromNumber(_Number);
Console.ReadLine();
}
private void _PlandromString(string _OldString)
{
string _NewString = string.Empty;
try
{
for (int i = _OldString.Length - 1; i >= 0; i--)
{
_NewString += _OldString[i];
}
if (_OldString.Equals(_NewString))
Console.WriteLine("String is palindrome");
else
Console.WriteLine("String is not palindrome");
}
catch (Exception Ex)
{
Ex.Message.ToString();
}
}
private void _PlandromNumber(long _Number)
{
long _OldNumber, _Reverse = 0, _Reminder;
_OldNumber = _Number;
try
{
while (_Number != 0)
{
_Reminder = _Number % 10;
_Reverse = _Reverse * 10 + _Reminder;
_Number /= 10;
}
if (_OldNumber == _Reverse)
Console.WriteLine("Number is palindrome");
else
Console.WriteLine("Number is not palindrome");
}
catch (Exception EX)
{
EX.Message.ToString();
}
}
}
 
Output: 
 
 
Answers (2)