Author : Rahul
Write a program to print the reverse of the number
Program:
using System;
namespace ProgrammingQuestion
{
class Program
{
static void Main(string[] args)
{
//Variable Declaration
string checkVal;
int checkNum, digit, reverseNum = 0, tempNum = 0, power;
//User Input
Console.Write("Enter Number:");
checkVal = Console.ReadLine();
checkNum = Convert.ToInt32(checkVal);
//Reverse Number Logic
tempNum = checkNum;
while (tempNum > 0)
{
digit = tempNum % 10;
power = GetPower(tempNum);
reverseNum = reverseNum + (int)Math.Pow(10, power - 1) * digit;
tempNum = tempNum / 10;
}
//Print Result
Console.WriteLine($"Reverse of the Number:{reverseNum}");
Console.Read();
}
//Method is used to get the number of digit of the number
private static int GetPower(int number)
{
int pow = 0;
while (number > 0)
{
pow++;
number = number / 10;
}
return pow;
}
}
}
Output:
Enter Number:1234
Reverse of the Number:4321