Pages

Monday, 29 January 2018

C# Program to Print Reverse Of a Given Number

C# Program to Print 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();
        }
    }

}