Pages

Wednesday, May 1, 2013

How to write C# program to reverse an integer


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

namespace ConsoleApplication2
{
    class reverse
    {
        public static void Main(string[] args)
        {
            int number;
            int rev = 0, a;
            Console.WriteLine("Enter the number to be reversed");
            number = Convert.ToInt32(Console.ReadLine());
            while (number > 0)
            {
                a = number % 10;
                rev = rev * 10 + a;
                number = number / 10;
            }
            Console.WriteLine("Reverse of Inetger" + sum);
            Console.ReadKey();
        }
    }
}

No comments:

Post a Comment