Palindrom program in C#

A palindrome number is a number that is same after reverse. For example 121, 12321, 343, 232, 545 are the palindrome numbers.

Let’s see the palindrome program in C#. In this program, we will get an input from the user and check whether number is palindrome or not.

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

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int num, sum = 0, temp, i;
Console.WriteLine(“enter the number:”);
num = Convert.ToInt32(Console.ReadLine());
temp = num;
while (num != 0)
{
i = num % 10;
sum = sum *10+ i ;
num = num / 10;
}
if (temp == sum)
Console.WriteLine(“palindrom“, sum);
else
{
Console.WriteLine(“not palindrom”, sum);
}
}

}
}

OutPut :

Enter the number=123
Number is not Palindrome.

Enter the Number=12321
Number is Palindrome.

3 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *