# reverse a number using recursion in c#

Csharp program for reverse a number using recursion . Here problem description and other solutions.

// Include namespace system
using System;
// Csharp program for
// Reverse a number using recursion
public class ReverseNumber
{
// This is reversing a number elements recursively
public int reverseNum(int number, int result)
{
// Base condition to stop the recursion process
if (number > 0)
{
// Recursive function call
return this.reverseNum((int)(number / 10),
result * 10 + (number % 10));
}
// When no digit remaining
return result;
}
// This is handling the request process of reverse number digit
public int reverse(int number)
{
// Display given number
Console.WriteLine("\nBefore Number : [" + number + "]");
if (number < 0)
{
// Handle negative number
return -this.reverseNum(-number, 0);
}
else
{
return this.reverseNum(number, 0);
}
}
public static void Main(String[] args)
{
// Test Case
var number = 12345;
// After reverse
Console.WriteLine("After Number  : [" + number + "]");
// After reverse
Console.WriteLine("After Number  : [" + number + "]");
// After reverse
Console.WriteLine("After Number  : [" + number + "]");
// After reverse
Console.WriteLine("After Number  : [" + number + "]");
}
}

Output

Before Number : [12345]
After Number  : [54321]

Before Number : [78942]
After Number  : [24987]

Before Number : [1020]
After Number  : [201]

Before Number : [-28]
After Number  : [-82]

## Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.