展开全部
#include <stdio.h>
// 将十进制数decimal转换为k进制数,并以字符串形式存放在字符数组s中
char *CountRule(unsigned number,unsigned k,char *s) {
int ch,i,n = 0;
if(k > 36) {
s[0] = '\0';
return s;
}
while(number) {
ch = number%k;
if(ch > 9) s[n] = ch - 10 + 'A';
else s[n] = ch + '0';
number /= k;
++n;
}
s[n] = '\0';
for(i = 0; i < n/2; ++i) {
ch = s[i];
s[i] = s[n - i - 1];
s[n - i - 1] = ch;
}
return s;
}
int main() {
char s[256],t[35];
int i = 0;
printf("输入一个字符串:");
gets(s);
while(s[i]) {
printf("0X%X\t%o\t%s\n",s[i],s[i],CountRule(s[i],2,t));
++i;
}
return 0;
}
追问
谢谢
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询