C 输出指定字母ASCII码与字母ASCII码表
一共这里是两道题,两道题都要求输出ascii码对应的十六进制,八进制,十进制,前面一道异常,非常,超级的……简单。而后面一道对输出格式有要求,所以慢慢修改探究出一个和答案差不多格式的了。
关于第二题的效果图:
第一题:
1#include <stdio.h>
2
3int main(void)
4{
5 char input;
6
7 printf("Print a English word: ");
8 scanf("%c", &input);
9 printf("%c dec: %d oct: %o hex: %x", input, input, input, input);
10 return 0;
11}
12
其实只是用了不同输出而已,可以参考:C 总结一下 类型与格式说明符对应表
第二题略烦
1#include <stdio.h>
2
3int main(void)
4{
5 int i;
6 char ascii;
7 i = 1;
8 ascii = 'A';
9
10 printf(" 结果为\n");
11 printf("char dec oct hex char dec oct hex char dec oct hex\n");
12
13 while (ascii <= 'Z') {
14 if (i % 3 != 0)
15 printf(" %c---%d-----%o-----%x ", ascii, ascii, ascii, ascii);
16 else
17 printf(" %c---%d-----%o-----%x\n", ascii, ascii, ascii, ascii);
18 ascii++;
19 i++;
20 }
21 return 0;
22}
23
24
评论 (0)