#include
int main()
{
char character;
printf("请输入字符:");
while((character=getchar())!=EOF)
{
if(('a'<=character && character<='z')||('A'<=character && character<='Z'))
{
printf("字符%c的ACSII码为:%d\n", character, character);
}
else if(('0'<=character && character<='9'))
{
printf("数字为:%d\n", character-'0');
}
else
{
printf("输入错误!\n");
}
printf("请输入字符:");
fflush(stdin);
}
return 0;
}
运行结果如下:
#include
main()
{
char c;
printf("请输入字符:");
scanf("%c",&c);
if(c>='A'&&c<='z')
printf("%c的ACSII码为:%d\n",c);
else
if(c>='0'&&c<='9')
printf("%d\n",c);
else
printf("请重新输入!");
}