Q:

Write C# program to check whether a number is palindrome or not

0

Write C# program to check whether a number is palindrome or not

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
public class csharpExercise
{
    static void Main(string[] args)
    {
        int num, i, rev;
 
        // Reading a number from user
        Console.Write("Enter any number: ");
        num = Convert.ToInt32(Console.ReadLine());
 
        rev = num;
        for (i = 0; num > 0; num = num / 10)
        {
            i = i * 10;
            i = i + (num % 10);
        }
 
        //Checking if reverse number is equal to original num or not.
        if (rev == i)
            Console.WriteLine(rev+" is a Palindrome Number.");
        else
            Console.WriteLine(rev + " is not a Palindrome Number.");           
 
 
        Console.ReadLine();
    }
}

Result:

Enter any number: 121

121 is a Palindrome Number.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write C# program to print number in words... >>
<< Write C# program to check whether a number is Prim...