Enter a Number : 123 Reverse of Entered Number : 321
This is a C# Program to get a number and display the number with its reverse.
This C# Program Gets a Number and Display the Number with its Reverse.
Here we obtain a number from the user and display the digits in the reverse order.
Here is source code of the C# Program to Get a Number and Display the Number with its Reverse. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * 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(); } } }
In this C# program, we are reading the number using ‘num’ variable. Multiply the value of ‘reverse’ variable by 10 and add this value of reverse variable with the modulus of the value of ‘reverse’ variable by 10. Compute the division of the value of ‘num’ variable by 10. Print the number with its reverse order.
Enter a Number : 123 Reverse of Entered Number : 321