Created
December 31, 2016 11:53
-
-
Save bigworld12/bc7d4c4cf29e39dfdd27afd05ec5c73a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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