C#使用栈进行十以内的进制转换

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://www.cnblogs.com/ahaoboy/p/5965298.html