进制转换
求教大佬们这个代码怎么修改可以完美转换十六进制
#include <stdio.h>
#include <iostream>
using namespace std;
int main () {
int n , p;
printf ("输入进制为:");
scanf ("%d",&p);
printf ("输入数字为:");
cin >> n;
int y = 0 , product = 1 ;
while (n != 0) {
y = y + (n%10)*product;
n = n / 10;
product = product * p ;
}
printf ("转化为十进制为:");
cout << y << endl;
int z[40], num = 0;
int m;
printf ("输出进制为:");
scanf ("%d",&m);
do {
z [num++] = y % m;
y = y / m;
} while (y != 0);
printf ("输出数字为:");
for (int i = num-1; i >= 0; i--){
printf ("%d",z[i]);
}
return 0;
}