从键盘输入一个字符,若该字符是小写字母,输出“该字符 is a lower case letter.”,若该字符是大写字母,输出“该字符 is a capital letter.”,若既不是小写字母也不是大写字母,则输出“该字符 is the other one.”。
输入一个字符输出该字符的类型样例输入?样例输出? is the other one.
请问这个怎么写?
C语言的字符类型char缺省就是存储的ASCII不用转换的
另外,C语言本身提供一套判断字符的函数的(不用自己写的)
程序很简单的
#include<stdio.h>
#include<ctype.h>
int main()
{
char c;
c=getchar();
if (islower(c))
printf("该字符 is a lower case letter.\n");
else
if (isupper(c))
printf("该字符 is a capital letter.\n");
else
printf("该字符 is the other one.\n");
return 0;
}
若要自己写判断也简单的,如
if(islower(c))
可用
if(c>='a' && c<='z')