Support us on YouTube by Subscribing our YouTube Channel. Click here to Subscribe our YouTube Channel

Sunday 19 October 2014

Reverse a Number in C#

In this Blog, We will learn How to reverse a no. using C#.

using System;

namespace ReverseNo
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter a No. to reverse");
            int Number = int.Parse(Console.ReadLine());
            int Reverse = 0;
            while(Number>0)
            {
                int remainder = Number % 10;
                Reverse = (Reverse * 10) + remainder;
                Number = Number / 10;
            }
            Console.WriteLine("Reverse No. is {0}",Reverse);
            Console.ReadLine();
        }
    }
}
Preview:
[Download Source Code via Google Drive]

Watch Video:

1 comment:

  1. I came up with the same algorithm. The only thing is, if you enter an integer that begins with one or more zeros, the loop will not include any of those zeros, it will terminate. So, is there a way to get it to include zeros at the beginning without using a string?

    ReplyDelete

Subscribe us on YouTube

Subscribe Now

Popular Posts

Contact us

Name

Email *

Message *

Like us on Facebook