Home / Programs / Program to reverse number in C#
🚀 Programming Example

Program to reverse number in C#

👁 366 Views
💻 Practical Program
📘 Step Learning

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.

💻 Program Code

using System;  
  public class ReverseExample  
   {  
     public static void Main(string[] args)  
      {  
       int  n, reverse=0, rem;           
       Console.Write("Enter a number: ");      
       n= int.Parse(Console.ReadLine());     
       while(n!=0)      
       {      
        rem=n%10;        
        reverse=reverse*10+rem;      
        n/=10;      
       }      
       Console.Write("Reversed Number: "+reverse);       
    }  
  }  
                        

🖥 Program Output

Enter a number: 234  
Reversed Number: 432
                            

📘 Explanation

None
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.