Interview: Write Palindrome Program
This is the most common program which will be asked for a fresher to the programming world.
Following are some of the steps to achieve a Palindrome program algorithm
- Read the number from the user using the console (in our case)
- Hold the number in a temporary variable
- Reverse the number
- Compare the temporary number with a reversed number
- If both numbers are same, print palindrome number. Else print not a palindrome number
using System;
public class PalindromeExample
{
public static void Main(string[] args)
{
int n,r,sum=0,temp;
Console.Write("Enter the Number: ");
n = int.Parse(Console.ReadLine());
temp=n;
while(n>0)
{
r=n%10;
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
Console.Write("Number is Palindrome.");
else
Console.Write("Number is not Palindrome");
}
}
Output:
Enter the Number=151 Number is Palindrome. Enter the number=123 Number is not Palindrome.
Happy Coding 🙂

