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# .
- 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 num, temp, remainder, reverse = 0;
- Console.WriteLine("Enter an integer \n");
- num = int.Parse(Console.ReadLine());
- temp = num;
- while (num > 0) {
- remainder = num % 10;
- reverse = reverse * 10 + remainder;
- num /= 10;
- }
- Console.WriteLine("Given number is = {0}", temp);
- Console.WriteLine("Its reverse is = {0}", reverse);
- Console.ReadLine();
- }
- }
- }
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.