static void Main(string[] args) {
int n,m;
while (true) {
Console.WriteLine("请输入要转换的数和进制,用英文空格分开:");
string s = Console.ReadLine();
string[] str = s.Split(' ');
n = Convert.ToInt32( str[0] );
m = Convert.ToInt32( str[1] );
Console.WriteLine(n+"的m进制为:"+test3(n,m));
}
public static string test3(int num, int fomat) {
Stack s = new Stack();
while (num != 0) {
int t = num % fomat;
s.Push(t);
num = (num-t)/fomat;
}
int n = s.Count;
string res = "";
for (int i = 0; i < n; i++) {
res += s.Pop();
}
return res;
}
![](https://images2015.cnblogs.com/blog/998605/201610/998605-20161015205151578-51550843.png)