Search This Blog

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

C# Program to Print Reverse Of a Given Number



C# program to find reverse of a given number

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


7 comments: