Skip to content

Instantly share code, notes, and snippets.

@bigworld12
Created December 31, 2016 11:53
Show Gist options
  • Save bigworld12/bc7d4c4cf29e39dfdd27afd05ec5c73a to your computer and use it in GitHub Desktop.
Save bigworld12/bc7d4c4cf29e39dfdd27afd05ec5c73a to your computer and use it in GitHub Desktop.
static void Main(string[] args)
{
int num = int.Parse(Console.ReadLine());
int result = Reverse(num);
Console.WriteLine("Reversed Number : {0}",result);
Console.ReadKey();
}
static int Reverse(int n)
{
int result = 0;
Reverse(n , ref result);
return result;
}
static void Reverse(int n , ref int result)
{
if (n != 0)
{
int remainder = n % 10;
result = result * 10 + remainder;
//recursion
Reverse(n / 10 , ref result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment