Reverse Number Program in C#
Advertisements
Reverse a Number Program in C#
To reverse any number we need to calculate remainder of number and the apply formula for reverse any number.
Formula
Remainder = Number % 10; Reverse = (Reverse * 10) + remainder; Number = Number / 10;
Reverse a Number Program in C#
using System; namespace Reverse_Num { class Program { static void Main(string[] args) { Console.WriteLine("Enter any Number: "); int num = int.Parse(Console.ReadLine()); int rev = 0; while(num>0) { int rem = Number % 10; rev = (rev * 10) + rem; num = num / 10; } Console.WriteLine("Reverse Number is: {0}",rev); Console.ReadLine(); } } }
Output
Enter any Number: 154 Reverse Number is: 451
Output
Enter any Number: 247 Reverse Number is: 742
Google Advertisment