C Sharp Program to reverse number

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

C# Program to reverse number

We can reverse a number in C# using loop and arithmetic operators. In this program, we are getting number as input from the user and reversing that number.

Let's see a simple C# example to reverse a given number.

 
  1. using System;  
  2.   public class ReverseExample  
  3.    {  
  4.      public static void Main(string[] args)  
  5.       {  
  6.        int  n, reverse=0, rem;           
  7.        Console.Write("Enter a number: ");      
  8.        n= int.Parse(Console.ReadLine());     
  9.        while(n!=0)      
  10.        {      
  11.         rem=n%10;        
  12.         reverse=reverse*10+rem;      
  13.         n/=10;      
  14.        }      
  15.        Console.Write("Reversed Number: "+reverse);       
  16.     }  
  17.   }  

Output:

Enter a number: 234  
Reversed Number: 432