C# Program To Reverse A Number

In this blog, we will write a C# program to reverse a number.
 
Reverse a Number in C# Code
 
 First it reverses a number. This code sample shows youhow  to reverse a number in C# .
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. namespace Reverse_Number {  
  7.     class Program {  
  8.         static void Main(string[] args) {  
  9.             int num, temp, remainder, reverse = 0;  
  10.             Console.WriteLine("Enter an integer \n");  
  11.             num = int.Parse(Console.ReadLine());  
  12.             temp = num;  
  13.             while (num > 0) {  
  14.                 remainder = num % 10;  
  15.                 reverse = reverse * 10 + remainder;  
  16.                 num /= 10;  
  17.             }  
  18.             Console.WriteLine("Given number is = {0}", temp);  
  19.             Console.WriteLine("Its reverse is = {0}", reverse);  
  20.             Console.ReadLine();  
  21.         }  
  22.     }  
  23. }  
Now run the Reverse  Number Code
 
Click On Start button
 
 
Open the debug console panel
 
 
Output the Reverse a Number Code
 
 
I hope you understood how to Reverse a Number using C# Code.


Next Recommended Reading Reverse a Number and String in C#