Reverse a number with do while loop in CSharp
Description
The following code shows how to reverse a number with do while loop.
Example
/*w w w .j a va 2 s . c o m*/
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.