C#.Net Code to get reverse of a Number
In this post, here is the C#.Net code to get the reverse of a number. Getting Reverse of a string is quite easy using string functions but for a number it differs.
Here we will see how to get reverse of a number without using any built-in methods.
You can also use this method while checking whether the number is Palindrome.
If the input number and the reversed input number are same, then the number is said to be a Palindrome.
/// <summary>
/// Method to get reverse of a number
/// </summary>
/// <param name=”Num”>Number to be reversed</param>
/// <returns>reversed input number</returns>
public int ReverseOfNum(int Num)
{
int RevNum = 0;
int rem = 0;
while (Num > 0)
{
//for getting remainder by dividing with 10
rem = Num % 10;
//for getting quotient by dividing with 10
Num = Num / 10;
//multiplying the sum with 10 and adding remainder
RevNum = RevNum * 10 + rem;
}
return RevNum;
}