## C# Program to Reverse a Number

Most of the IT companies check the coding skills and problem-solving skills as well along with the theoretical interview questions. Sometimes you are free to write the pseudo code and sometimes you are asked to write the complete program either on any paper or any editor.

This question is asked in the coding interview to write the program. Here you can find the program as well as a live running program so that you can test the program immediately.

Watch our videos here

#### Question:

How can you reverse a given number? Write a program to reverse a given number using recursion.

### C# Program To Reverse a Number

```
```

// Author 	: Tech Point Fundamentals
// Website 	: www.techpointfunda.com
// Question : How can you reverse a given number? Write a program to reverse a given number.
// Demo		: Reversing a Number

using System;

public class Program
{
public static void Main()
{
int inputNumber = 9845;

Console.WriteLine("Input Number : " + inputNumber);
Console.WriteLine("Reverse Number : " + ReverseNumber(inputNumber));
Console.WriteLine("Reverse Number using Recursion : ");
ReverseNumberRecursion(inputNumber);
}

public static int ReverseNumber(int inputNumber)
{
int reverse = 0;
int reminder;

while (inputNumber != 0)
{
reminder = inputNumber % 10;
reverse = (reverse * 10) + reminder;
inputNumber /= 10;
}

return reverse;
}

public static void ReverseNumberRecursion(int inputNumber)
{
if (inputNumber <= 0)
{
return;
}
else
{
Console.Write(inputNumber % 10);
ReverseNumberRecursion(inputNumber / 10);
}
}
}

```
```

#### Output:

Input Number : 9845
Reverse Number : 5489
Reverse Number using Recursion :
5489

### Live Demo

#### Recommended Articles

SOLID Design Principles