题目:
从键盘任意输入一个字符,编程判断该字符是数字字符、英文字母、空格还是其他字符。
**输入格式要求:提示信息:“Press a key and then press Enter:”
**输出格式要求:“It is an English character!\n” “It is a digit character!\n” “It is a space character!\n” “It is other character!\n”
程序运行示例1如下:
Press a key and then press Enter:A
It is an English character!
程序运行示例2如下:
Press a key and then press Enter:2
It is a digit character!
程序运行示例3如下:
Press a key and then press Enter:
It is a space character!
程序运行示例4如下:
Press a key and then press Enter:#
It is other character!
【PS:无输入时,显示It is a space character!】
程序:
#include <stdio.h>
int main()
{
char a;
printf("Press a key and then press Enter:");
a = getchar();
if ('A' <= a && a <= 'Z')
printf("It is an English character!\n");
else if ('a' <= a && a <= 'z')
printf("It is an English character!\n");
else if ('0' <= a && a <= '9')
printf("It is a digit character!\n" );
else if (a == ' ')
printf("It is a space character!\n");
else if (a=10)//当然a=='\n'也ok啦
printf("It is a space character!\n");//无输入
else
printf("It is other character!\n");
return 0;
}
这题中,无输入时 是 换行符。
以及,无论如何
赋值运算符和关系运算符不要搅!
这是。
底线。