top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Write a program to reverse a number using C#

0 votes
307 views

using System;

namespace Learn
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter a Number");
            int numb = int.Parse(Console.ReadLine());
            int reverse = 0;
            while (numb > 0)
            {
                int rem = numb % 10;
                reverse = (reverse * 10) + rem;
                numb = numb / 10;
               
            }
            Console.WriteLine("Reverse number={0}", reverse);
            Console.ReadLine();
        }
    }
}

 

Output
----------

Enter a Number
4567
Reverse number=7654

posted Feb 20, 2017 by Shivaranjini

  Promote This Article
Facebook Share Button Twitter Share Button LinkedIn Share Button


Related Articles

using System;

namespace Learn
{
    class Program
    {
        static void Main(string[] args)
        {
            string Str, Revstr = ""
            int Length;

            Console.Write("Enter A String : ");
            Str = Console.ReadLine();

            Length = Str.Length - 1;
            
            while (Length >= 0)
            {

                Revstr = Revstr + Str[Length];
                Length--;

            }

            Console.WriteLine("Reverse  String  Is  {0}", Revstr);

            Console.ReadLine();

        }
    }
}

 

OUTPUT
-------------

Enter A String : HELLO
Reverse  String  Is  OLLEH

READ MORE
...