This simple program will help you to find that given number is Palindrome using C#. Just copy and paste this program to your C# file and run it.
Code to check Palindrome :
using System;
using System.Text;
using System.Collections;
using System.Data;
namespace Console_App
{
public class clspalindrome
{
public static void Main()
{
try
{
Console.WriteLine("Program for palindrome");
Console.WriteLine("Enter the number to check palindrome:");
int Number = Convert.ToInt32(Console.ReadLine());
int n, digit, revNumber = 0;
string s;
n = Number;
do
{
digit = Number % 10;
revNumber = revNumber * 10 + digit;
Number /= 10;
} while (Number != 0);
Console.WriteLine("");
Console.WriteLine("Reverse of the given number = {0}", revNumber);
Console.WriteLine("");
if (n == revNumber)
Console.WriteLine("Congrats, The number is a palindrome");
else
Console.WriteLine("Sorry, The number is not a palindrome");
}
catch (Exception ex)
{
//handle exception here
}
Console.ReadLine();
}
}
}
No comments:
Post a Comment