Latest Post

Tuesday, 3 January 2017

How to find the reverse of a number[C#]

Write a program in C# to find the reverse of a number.

Following is the simple C# code :

class Lab
    {
        static void Main(string[] args)
        {
            int Reverse = 0;
            Console.WriteLine("Enter a Number that want to reverse");
            int Number = int.Parse(Console.ReadLine());

            while (Number > 0)
            {
                int remainder = Number % 10;
                Reverse = (Reverse * 10) + remainder;
                Number = Number / 10;
            }
            Console.WriteLine("Reverse Number is {0}", Reverse);
            Console.ReadLine();

        }
    }

Output:-

Enter a Number that want to reverse
74865
Reverse Number is 56847


Government Jobs