14+ C# Programs to Reverse a Number

This post contains a total of 14+ Hand-Picked C# Programs to Reverse a Number with Source Codes. All the programs are made using C Sharp Programming Language.

You can use the source code of these programs for educational purpose with credits to the original owner.

Related Posts

Click a Code to Copy it.

1. By ZARATHAN

Made by ZARATHAN. C# Program for Reversing a input number. ( Source )

1234
4321
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static int reverse(int num)
        {
            int reversed = num % 10;
            int currentDigit = 1;
            
            while(true)
            {
                int temp = 0;
                currentDigit *= 10;
                
                if (num < currentDigit)
                    break;
                    
                temp = temp + (num / currentDigit) % 10;
                reversed = reversed * 10 + temp;
            }
            return reversed;
        }
        static void Main(string[] args)
        {
            int num = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine(reverse(num));
        }
    }
}

2. By Nima Bazgir

Made by Nima Bazgir. Program that reads a two-digit number and print the sum of digits and the reverse of number. ( Source )

Enter a 2 digit number: 
Reverse is 36	 Sum is 9
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sololearn
{
    class Program
    {
        static void Main(string[] args)
        {
            int num, n1, n2;
            Console.WriteLine("Enter a 2 digit number: ");
            num = int.Parse(Console.ReadLine());
            n1 = num % 10;
            n2 = num / 10;
            num = (n1 * 10)+n2;
            Console.WriteLine("Reverse is {0}\t Sum is {1}",num,n1+n2);
        }
    }
}

3. By laura

Made by laura. C# Program to reverse a number using for loop, the input limit is 10 digits. ( Source )

Input a number: The number you entered is : 653

The number in reverse order: 356
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            /* this is more practice on for loops.  take a number and reverse it.  limit is 10 digits*/
            
             int number = 0;
            int[] arr = new int[10];
            int count = 0;
            Console.Write("Input a number: ");
            number = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("The number you entered is : {0}", number);
            

            for(int s = 0; s < arr.Length; s++)
            {
               
                arr[s] = number % 10;
                number = number / 10;
                count++;
                if (number == 0)
                    break;
                
                
            }

            Console.WriteLine();
            Console.Write("The number in reverse order: ");

            for (int s = 0; s < count; s++)
            {
                Console.Write("{0}", arr[s]);
            }

            Console.WriteLine(); 
            
  
        }
    }
}

4. Musa AbdulKareem

Made by Musa AbdulKareem. ( Source )

564
465
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            string number = Console.ReadLine();
            string rnumber = "";
            for (int i = 0; i < number.Length; i++)
            {
                rnumber += number[number.Length-1-i];
            }
            Console.WriteLine(rnumber);
        }
    }
}

5. By Mohammad Amin Zamani

Made by Mohammad Amin Zamani. ( Source )

Your Number:
3542
Reverse Number:
2453
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
             int number=Convert.ToInt32(Console.ReadLine());
             Console.WriteLine("Your Number:\n" + number + "\nReverse Number:");
             while(number%10==0){number/=10;}
            while(number>=1){Console.Write(number%10);number/=10;}
        }
    }
}

6. By Pavel Derevianko

Made by Pavel Derevianko. Enter a non-negative integer natural number to reverse it. ( Source )

4366
6634
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Sololearn
{
    class Program
    {
        static void Main(string[] args)
        {
            var text = Console.ReadLine();
            int number = int.Parse(text);
            if(number > 0 && number < 1000000001)
            {
                for (int i = 0, one = 1; i < text.Length; i++, one = one * 10)
                    Console.Write(number % (one * 10) / one);
            }
            else Console.Write("It is wrong number, try again");
        }
    }
}

7. By Rex

Made by Rex. ( Source )

45674
47654
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoloLearn
{
	class Program
	{
		static void Main(string[] args)
		{int n; int r=0; int i;
n=Convert.ToInt32(Console.ReadLine());
		 while(n>=1)
			{i=n%10;
			 r=r*10;
			 r=r+i;
			 n=n/10;}
			Console.WriteLine(r);
		}
	}
}

8. By Sanjeev Kumar

Made by Sanjeev Kumar. Run the Program and input a number. The codes will reverse your number. ( Source )

 The reverse of '5524' = 4255
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Reverse_Number
{
    class Program
    {
        static void Main(string[] args)
        {

int a=Convert.ToInt32(Console.ReadLine());

         int reverse=0;  
         int sum=0;
         int n=a;
         while(n>0)
         {
         int x=n%10;
         sum +=x;
         reverse=reverse*10+x;
         n=n/10;
         }
Console.Write(" The reverse of '"+a+"' = "+reverse+"\n");

Console.Write("\n The sum of digits of '"+a+"' = "+sum);
         }
     }  
}

9. By Tran Vi Lap

Made by Tran Vi Lap. ( Source )

Your input was: 34563
Result: 36543
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
	class Program
	{
		static void Main(string[] args)
		{
		    
		    int x = Convert.ToInt32( Console.ReadLine());
		    Console.WriteLine("Your input was: "+ x);
		    Console.WriteLine("Result: "+Reverse(x));
    			
		}
		static private int Reverse(int x) {
        long result = 0;
        while(x!= 0)
        {
            int lastInt = x%10;
            result = result*10+ lastInt;
            x=x/10;
        }
        if (Math.Pow(-2,31)<=result && result<= Math.Pow(2,31))
            return (int)result;
        else
            return 0;
    }
	}
}

10. By Payam Mohammadi

Made by Payam Mohammadi. Program to reverse a input number using C#. ( Source )

7655
5567
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ReverseNumber
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			int number = Convert.ToInt32(Console.ReadLine());
			Console.WriteLine(reverseNumWithwhile(number));
			Console.WriteLine(reverseNumWithFor(number));
			

		}

		public static int reverseNumWithFor(int number) {
			int reverse = 0;
			for (; number > 0;) {
				int mod = number % 10;
				reverse *= 10;
				reverse += mod;

				number /= 10;
			}
			return reverse;
		}

		public static int reverseNumWithwhile(int number) {
			int reverse = 0;
			while (number > 0) {
				int mod = number % 10;
				reverse *= 10;
				reverse += mod;

				number /= 10;
			}
			return reverse;
		}


	}
}

11. By Sonya Markina

Made by Sonya Markina. ( Source )

24412
21442
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApplication15
{
    class Program
    {
        static void Main(string[] args)
        {
            int myInt = int.Parse(Console.ReadLine());
            Console.WriteLine(myInt);
            int myInt2 = Reverse(myInt);
            Console.WriteLine(myInt2);
            Console.ReadLine();
        }
        static int Reverse(int myInt)
        {
            char[] myChar = myInt.ToString().ToCharArray();
            Array.Reverse(myChar);
            return int.Parse(new string(myChar));
        }
    }
}

12. By Blank

Made by Blank. Prints a number to its reverse. ( Source )

5
4
3
2
1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Sololearn
{
    class Program
    {
        static void Main(string[] args)
        {
            int a=5;
            for(int i=a;i>=1;i--)
            {
                Console.WriteLine(i);
                
            }
        }
    }
}

13. By Sololearn

Made by Sololearn. Input the number you want to reverse in int num = 45763. ( Source )

36754
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            //sample number
            int num = 45763;
            
            int reverse = 0;  
            while(num > 0)  
            {  
                // use modulus operator to strip off the last digit and create the reversed number
                reverse = (reverse * 10) + num % 10;  
                num = num / 10;  
            }  
            Console.WriteLine(reverse);  
        }
    }
}

14. By Artemis Ariamehr

Made by Artemis Ariamehr. ( Source )

7457
7547
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace SoloLearn
{
    class Program
    {
    
        static void Main(string[] args)
        {
            int input  =Convert.ToInt32(Console.ReadLine());
            int i,output=0;
            
            while(input >0)
            {
               i=input %10;
               input /=10;
               output=output*10+i;
                
            }
            Console.WriteLine(output.ToString());
        }
    }
}

15. By miracles information.R

Made by miracles information.R. ( Source )

1
3
7
5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Sololearn
{
    class Program
    {
        static void Main(string[] args)
        {
            int []mynum = {5,7,3,1};
            Array.Reverse(mynum);
            foreach (int i in mynum)
            {
                Console.WriteLine(i);
            }
        }
    }
}