C# program to reverse the number entered by the user, then displays the reversed number on the screen.
C# Program Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | class Program { public static void Main() { int nreversed = 0, nbr; Console.Write("Enter an integer number: "); nbr = Convert.ToInt32(Console.ReadLine()); while (nbr != 0) { nreversed = nreversed * 10; nreversed = nreversed + nbr % 10; nbr = nbr / 10; } Console.WriteLine("The number in reversed is = {0}",nreversed); Console.ReadLine(); } } |
Output:
1 2 3 4 | Enter an integer number: 12345 The number in reversed is = 54321 |