Palindrome Number in C Sharp

Palindrome Number

A palindrome number is a number which is the same as its reverse number.

For example,

111, 56765, 42424, 234565432, etc.

Algorithm:

  • Take the input from the user.
  • Store the number in a temporary variable.
  • Create the reverse of the number.
  • Compare both the numbers.
  • Print the number as a palindrome number, if both the numbers are the same.
  • Else print the number as a non-palindrome number.

Example:

using System;  
  public class Example  
   {  
     public static void Main(string[] args)  
      {  
          int num, x, sum=0, y;    
          Console.Write("Enter the Number: ");   
          num = int.Parse(Console.ReadLine());  
          y = num;      
          while(num >0)      
          {      
           x = num%10;      
           sum=(sum*10) + x;      
           num = num/10;      
          }      
          if(y==sum)      
           Console.Write("Palindrome Number.");      
          else      
           Console.Write("Not a Palindrome Number.");     
    }  
  }

Output:

Explanation:

In the above example, we are displaying the palindrome program in C#. We took input from the user which is then checked to be a palindrome number or not.