Display the digits of an integer in reverse order in CSharp
Description
The following code shows how to display the digits of an integer in reverse order.
Example
/* w ww . j ava2 s.c om*/
using System;
public class MainClass {
public static void Main() {
int num;
int nextdigit;
num = 198;
Console.WriteLine("Number: " + num);
Console.Write("Number in reverse order: ");
do {
nextdigit = num % 10;
Console.Write(nextdigit);
num = num / 10;
} while(num > 0);
Console.WriteLine();
}
}
The code above generates the following result.