This website completely moved to new platform. For latest content, visit www.programmingposts.com

Search this Site

19 Feb 2013

C# Program to Print Reverse Of a Given Number

C# PROGRAM TO PRINT THE REVERSE OF A GIVEN NUMBER

original post

using System;

namespace ReverseNumber
{
    class Program
    {
        static void Main(string[] args)
        {

            int num, rem, sum = 0, rev;
            Console.WriteLine("\n /** To Find Reverse Of a Number **/");
            Console.Write("\n Enter a number: ");
            num=Convert.ToInt32(Console.ReadLine());
            while (Convert.ToBoolean(num))
            {
                rem = num % 10;  //for getting remainder by dividing with 10
                num = num / 10; //for getting quotient by dividing with 10
                sum = sum * 10 + rem;
            }
            rev = sum;
            Console.WriteLine("\n The Reversed Number is: {0} \n\n", rev);
            Console.ReadLine();
        }
    }
}

Output:

For C Program : C Program To Find The Reverse Of a Given Number