Program to reverse the digits of a number in C Sharp/C#

By | April 3, 2012

Hi,

Use the following code if you want to reverse the digits of a number using C Sharp/C #.

using System;

class MainClass {
  public static void Main() {

    int urNum;

    int urdigits;

    urNum = 123;

    Console.WriteLine("Given Number: " + urNum);

    Console.Write("Reversed Number: ");

    do {

      urdigits = urNum % 10;

      Console.Write(urdigits);

      urNum = urNum / 10;

    } while(urNum > 0);

    Console.WriteLine();

  }
}

Output :
Given Number: 123
Reversed Number: 321

🙂

Leave a Reply

Your email address will not be published. Required fields are marked *