Bootstrap

ASCII码与字符的相互转化

1、输入一个ASCII码,输出对应的字符

#include <stdio.h>

int main(int argc, char const *argv[])

{

    char ch;

    printf("input  number: ");

    scanf("%d", &ch);

    printf("ASCII: %c\n",ch);

    return 0;

}

2、输入一个字符,输出对应的ASCII码 

#include <stdio.h>

int main(int argc, char const *argv[])

{

    char ch;

    printf("input letter: "); 

    scanf("%c", &ch); 

    printf("NUMBER: %d\n",ch);

    return 0;

}

3、输入一个ASCII码和一个字符,分别输出对应的字符和 ASCII码 

#include <stdio.h>
int main(int argc, char const *argv[])
{
    int a;
    char ch;
    printf("input letter and number: ");
    scanf("%c%d",&ch,&a); 
    printf("NUMBER: %d\n",ch);
    printf("ASCII: %c\n",a);
    return 0;
}

;