#include<iostream>
#include<string>
using namespace std;
//进制转换
void convto(char *s,int n,int b)
{
char bit[]=("0123456789ABCDEF");
int len;
if(n==0)
{
strcpy(s,"");
return ;
}
convto(s,n/b,b);
len=strlen(s);//只算有效的字符长度
s[len]=bit[n%b];
s[len+1]='\0';
}
int main(void)
{
char s[100];
int i,base,old;
cout<<"请输入十进制数:"<<endl;
cin>>old;
cout<<"请输入转换的进制:"<<endl;
cin>>base;
convto(s,old,base);
cout<<s<<endl;
return 0;
#include<string>
using namespace std;
//进制转换
void convto(char *s,int n,int b)
{
char bit[]=("0123456789ABCDEF");
int len;
if(n==0)
{
strcpy(s,"");
return ;
}
convto(s,n/b,b);
len=strlen(s);//只算有效的字符长度
s[len]=bit[n%b];
s[len+1]='\0';
}
int main(void)
{
char s[100];
int i,base,old;
cout<<"请输入十进制数:"<<endl;
cin>>old;
cout<<"请输入转换的进制:"<<endl;
cin>>base;
convto(s,old,base);
cout<<s<<endl;
return 0;
}