Wednesday, 14 October 2015

Reverse a number in C#

using System;
class Program
{
    public static void Main()
    {
        int num;
        int reverse = 0;
        Console.WriteLine("Please Enter a number for reverse");
        num = int.Parse(Console.ReadLine());
        while (num > 0)
        {
            int remainder = num % 10;
            reverse = (reverse * 10) + remainder;
            num = num / 10;
        }
        Console.WriteLine("Reverse of entered number is : {0}",reverse);
    }
}

No comments:

Post a Comment