using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 反序数
{
class Program
{
static void Main(string[] args)
{
//输入一个五位数的整数
Console.WriteLine("请输入一个五位数的整数(10000<n<99999 ) n= ");
uint n = Convert.ToUInt32(Console.ReadLine());
uint n1 = n % 10; //除以10取余数得到个位数字
n = n / 10; //整除以10变成四位数
uint n2 = n % 10; //除以10取余数得到十位数字
n = n / 10; //成为三位数
uint n3 = n % 10; //得到百位数
n = n / 10; //成为两位数
uint n4 = n % 10; //得到千位数
n = n / 10; //成为一位数
uint n5 = n % 10; //得到万位数
//形成并输出原整数的反序数
uint m = (((n1 * 10 + n2) * 10 + n3) * 10 + n4) * 10 +
n5;
Console.WriteLine ("反序后的是{0}",m);
Console.Read();
}
}
}
升级版
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 反序数
{
class Program
{
static void Main(string[] args)
{
//输入一个五位数的整数
Console.WriteLine("请输入一个五位数的整数(10000<n<99999 ) n= ");
uint n = Convert.ToUInt32(Console.ReadLine());
//形成并输出原整数的反序数
Console.Write("5位符号数为 {0}",n);
char c1=Convert.ToChar(n%10+'0'); //分离个位数
char c2 = Convert.ToChar(n / 10 % 10 + '0'); //分离十位数
char c3 = Convert.ToChar(n / 100 % 10 + '0'); //分离百位数
char c4 = Convert.ToChar(n / 1000 % 10 + '0'); //分离千位数
char c5 = Convert.ToChar(n / 10000 % 10 + '0'); //分离万位数
Console.WriteLine ("反序后的是{0}{1}{2}{3}{4}",c1,c2,c3,c4,c5);
Console.Read();
}
}
}