简单编程实现十进制转换任意进制

#include <iostream>
using namespace std;
int main()
{
    int t, d; //原数字,转换进制
    cin >> t >>d;
    if (t == 0) //当原数字是 0时,最后结果还是 0
	{
        cout << 0;
        return 0;
    }
    int s[100];
    int i = 0;
    while (t != 0)
	{
        s[i++] = t % d;
        t = t / d;
    }
    for (int j = i - 1; j >= 0; j--)
	{
        cout << s[j]; //一个个输出
    }
    return 0;
}

但只能计算d<=10的情况(即转换小于10的进制)

发布了92 篇原创文章 · 获赞 35 · 访问量 6358

猜你喜欢

转载自blog.csdn.net/CourserLi/article/details/104270996