算法思路:取余,再将余数逆序
#include <stdio.h> void m2n(int m, char* mNum, int n, char* nNum) { int i = 0; char c, *p = nNum; while(*mNum != '\0') { i = i * m + *mNum - '0'; mNum ++; } while(i) { *p = i % n + '0'; i /= n; p ++; } *p = '\0'; p --; while(p > nNum) { c = *p; *p = *nNum; *nNum = c; p --; nNum ++; } } int main(int argc, char* argv[]) { int m = 10; int n = 5; char* mNum = "8"; char nNum[50] = {0}; m2n(m, mNum, n, nNum); printf("%s", nNum); }