Program :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Reverse
{
class Program
{
static void Main(string[] args)
{
int num, rem, rev = 0;
Console.WriteLine("//How to get Reverse of a number in c# ?");
Console.WriteLine("Enter A number :");
num = Convert.ToInt32(Console.ReadLine());
if (num > 0)
{
for (int temp = num; temp != 0; temp /= 10)
{
rem = temp % 10;
rev = rem + (rev * 10);
}
Console.WriteLine("The Reverse of " + num + " is :" + rev);
}
else
Console.WriteLine("Enter A valid Number :\n");
Console.ReadKey();
}
}
}
Output :
//How to get Reverse of a number in c# ?
Enter A number :
12345
The Reverse of 12345 is :54321
Comments
Post a Comment