6 March 2014

Reverse a number c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter a value");
            int a = Convert.ToInt16(Console.ReadLine());
            int rev = 0, rem = 0;
            do
            {
                rem = a % 10;
                rev = rev * 10 + rem;
                a = a / 10;
            }
            while (a > 0);
            Console.WriteLine("the reversed no. is "+rev.ToString());
          
            Console.WriteLine("end");
            Console.ReadLine();
        }
    }
}

No comments:

Post a Comment