69,381
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
void Itob(int n,char s[],int b);
int main()
{
int n,b;
char s[20];
scanf("%d %d",&n,&b);
Itob(n,s,b);
return 0;
}
void Itob(int n,char s[20],int b)
{
int i,j;
i=0;
j=0;
char a;
int c;
while( n != 0 )
{
c= n % b;
(c < 10)?(s[i]= c+'0'):(s[i]=c-10+'A');
n = n / b;
i++;
}
s[i]= '\0';
i--;
while(i >= j)
{
a=s[i];
s[i]=s[j];
s[j]=a;
i--;
j++;
}
printf("%s\n",s);
system("pause");
}
#include <stdio.h>
void Itob(int n,char s[],int b);
int main()
{
int n,b;
char s[20];
scanf("%d %d",&n,&b);
Itob(n,s,b);
return 0;
}
void Itob(int n,char s[20],int b)
{
int i,j;
i=0;
j=0;
char a;
int c;
while( n != 0 )
{
c= n % b;
(c < 10)?(s[i]= c+'0'):(s[i]=c+'A');
n = n / b;
i++;
}
s[i]= '\0';
i--;
while(i >= j)
{
a=s[i];
s[i]=s[j];
s[j]=a;
i--;
j++;
}
printf("%s\n",s);
}