Write a program to get a number and display it reverse format in C#
example : - 987 ==> 789
using System;
namespace Test_Application
{
class Program
{
static void Main(string[] args)
{
int num, rev = 0;
Console.WriteLine("Enter the Number : ");
num = int.Parse(Console.ReadLine());
while (num != 0)
{
rev = rev * 10;
rev = rev + num % 10;
num = num / 10;
}
Console.WriteLine("Reversed Number is : " + rev);
Console.ReadLine();
}
}
}
Output:-
Enter a Number :- 987
Reversed Number is : 789
example : - 987 ==> 789
using System;
namespace Test_Application
{
class Program
{
static void Main(string[] args)
{
int num, rev = 0;
Console.WriteLine("Enter the Number : ");
num = int.Parse(Console.ReadLine());
while (num != 0)
{
rev = rev * 10;
rev = rev + num % 10;
num = num / 10;
}
Console.WriteLine("Reversed Number is : " + rev);
Console.ReadLine();
}
}
}
Output:-
Enter a Number :- 987
Reversed Number is : 789