满意答案
r454985002
2015.12.24
采纳率:47% 等级:8
已帮助:960人
#include #include #include int main(void){ long int digital, len, times; char ch[50]; while (true) { fputs("请输入一个十六进制数字 : ", stdout); gets(ch); for (times &#61; 1, len &#61; strlen(ch) - 1, digital &#61; 0; len >&#61; 0; --len) { ch[len] &#61; tolower(ch[len]); if (ch[len] >&#61; &#39;a&#39; && ch[len] <&#61; &#39;f&#39;) digital &#43;&#61; (ch[len] - 87) * times; else if (isdigit(ch[len])) digital &#43;&#61; (ch[len] - 48) * times; else { puts("无法识别的十六进制!"); break; } times *&#61; 16; } printf("%s &#61; %d\n\n", ch, digital); } return 0;}
00分享举报