递归_数制转换
原来是用C写的,我改成C#后,由于语言的不同,多少会有点差异,但是能实现功能!!! using System; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 递归_数制转换
{
class Program
{
static void Main(string[] args)
{
char[] s = new char[2];
int i = 0,b=0,old=0;
Console.WriteLine("请输入一个十进制数字");
old = int.Parse(Console.ReadLine());
Console.WriteLine("请输入转换的进制");
b = int.Parse(Console.ReadLine());
ConveTo(s,old,b);
Console.ReadKey();
}
static void ConveTo(char[] s, int n, int b)
{
//16进制需要的
string bit = "0123456789ABCDEF";
//char的长度 int len=0;
if (n == 0)
{
return;
}
ConveTo(s, n / b, b);
//截取字符
s[len]= bit[n % b];
//输出
Console.Write(s);
}
}
}
|
递归_数制转换
最新推荐文章于 2023-09-04 01:03:35 发布