C# Program for Reverse Number - c# - c# tutorial - c# net



How to write Reverse Number Programs in C# ?

  • It can reverse the number entered by the user and then prints the reversed number on the screen
 c sharp program to reverse number
  • Let's see a simple C# example to reverse a given number.

Example1:


          class Program  
    {  
        static void Main(string[] args)  
        {  
            Console.WriteLine("Enter a No. to reverse");  
            int Number = int.Parse(Console.ReadLine());  
            int Reverse = 0;  
            while(Number>0)  
            {  
                int remainder = Number % 10;  
                Reverse = (Reverse * 10) + remainder;  
                Number = Number / 10;  
            }  
            Console.WriteLine("Reverse No. is {0}",Reverse);  
            Console.ReadLine();  
        }  
    }  
          
          
          

Example2:

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);       
    }  }

C# examples - Output :

Enter a number: 234  
Reversed Number: 432

Example3:

/*
 * C# Program to Get a Number and Display the Number with its Reverse
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace Program
{
    class Program
    {
        static void Main(string[] args)
        {
            int num, reverse = 0;
            Console.WriteLine("Enter a Number : ");
            num = int.Parse(Console.ReadLine());
            while (num != 0)
            {
                reverse = reverse * 10;
                reverse = reverse + num % 10;
                num = num / 10;
            }
            Console.WriteLine("Reverse of Entered Number is: "+reverse);
            Console.ReadLine();
 
        }
    }
}

Output:

Enter a Number: 123
Reverse of Entered Number: 321

Related Searches to C# Program for Reverse Number