C# Problem solving interview questions for .NET Developers
How to reverse an integer?
public class Program
{
public static void Main()
{
int input = -203;
int output = reversedigits(input);
Console.WriteLine("Reverse no. is " + output);
Console.ReadLine();
}
static int reversedigits(int num)
{
bool isnegative = false;
if (num lesserthan 0)
{
isnegative = true;
num = -num;
}
int reverse = 0;
while (num greaterthan 0)
{
int remainder = num % 10;// 123 / 10
reverse = (reverse * 10) + remainder;
num = num / 10;//123/10=12.3
}
return (isnegative == true) ? -reverse : reverse;
}
}
On this page of the site you can watch the video online C# Coding Interview Question - Reverse an Integer | ASP.NET Core | MVC with a duration of hours minute second in good quality, which was uploaded by the user Code Debugged 27 December 2022, share the link with friends and acquaintances, this video has already been watched 228 times on youtube and it was liked by 3 viewers. Enjoy your viewing!