All Type Coding

Search Here

Palindrome program in c#

using System;
class Program
{
    static void Main(string[] args)
    {
        int num, rem, sum = 0, temp;
        
        Console.WriteLine("\n To Find a Number is Palindrome or not ");
        
        Console.Write("\n Enter a number: ");
        num = Convert.ToInt32(Console.ReadLine());
        temp = num;
        while (Convert.ToBoolean(num))
        {
            rem = num % 10;  
            num = num / 10; 
            sum = sum * 10 + rem; 
        }
        Console.WriteLine("\n The Reversed Number is: {0} \n", sum);
        if (temp == sum) //checking whether the reversed number is equal to entered number
        {
            Console.WriteLine("\n Number is Palindrome \n\n");
            
        }
        else
        {
            Console.WriteLine("\n Number is not a palindrome \n\n");
        }
        Console.ReadLine();
    }
}
Output:



No comments :

Post a Comment