C#:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int i; string str, temp = "";
do
{
Console.Write("请输入一个小于100000的非负数: ");
str = Console.ReadLine();
try { i = Convert.ToInt32(str); }
catch { Console.WriteLine("你输入的不是数字!"); continue; }
if (i > 99999 || i < 0) { Console.WriteLine("输入的数值超出范围!"); continue; }
Console.WriteLine("是"+str.Length+"位数。");
Console.WriteLine("个位: " + i % 10);
Console.WriteLine("十位: " + (i / 10) % 10);
Console.WriteLine("百位: " + (i / 100) % 10);
Console.WriteLine("千位: " + (i / 1000) % 10);
Console.WriteLine("万位: " + i / 10000);
for (i = 0; i < str.Length; i++) { temp += str.Substring(str.Length - 1 - i, 1); }
Console.WriteLine("逆序数字: " + temp);
break;
} while (true);
Console.WriteLine("按任意键退出。");
Console.ReadKey();
}
}
}
运行效果如图
不过大家不要学我,我的程序有很多地方不妥