c语言入门问题,求大神解答🙏

从键盘输入任意一个字符,请用开关语句(switch)编程判断该字符是数字、大写字母、小写字母、空格或其他字符

#include<stdio.h>


void main()

{

char ch;

int a;

ch=getchar();

if(ch>='a'&&ch<='z')

ch='1';

if(ch>='A'&&ch<='Z')

ch='2';

if(ch==' ')

ch='3';

switch(ch)

{

case'1':

printf("小写字母\n");

break;

case'2':

printf("大写字母\n");

break;

case'3':

printf("空格\n");

break;

default:

printf("其他");

}

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2020-04-23

您好,很高兴回答您的问题。

对于您说的问题,确实是属于入门级别的问题,您要多多自己动手操作哦。而且switch 语句是有很多的限制条件的,个人认为不是很适合在您所说的这个题目中。建议用if-else语句很容易解决您说的问题,switch语句反而把问题弄复杂了。

追问

可是题目就是要求只用swith啊,😂

追答

这里有范围要求,用switch的话,还得要考虑一下,我来试试

追问

不用了,谢谢你,我自己已经想到了

本回答被网友采纳
第2个回答  2020-04-23
系语言入门问题,这是专业的电脑知识,你必须认真的学习才能提高自己的领会能力。
第3个回答  2020-05-05
#include<stdio.h>
void main()
{
char ch;
printf("Please input a character : \n");
ch=getchar();
ch= ch=32 || ch>=48 && ch<=57 || ch>=65 && ch<=90 || ch>=97 && ch<=122 ? ch/5 : -6;
switch (ch)
{
case 6: printf ("This is a blank space character!\n");break;
case 9:
case 10:
case 11: printf ("This is a number!\n");break;
case 13:
case 14:
case 15:
case 16:
case 17:
case 18: printf ("This is a capital letter!\n");break;
case 19:
case 20:
case 21:
case 22:
case 23:
case 24: printf ("This is a lowercase letter!\n");break;
default:printf("This is a other character!\n");
}
}
//用ASCLL码来做这道题追问

哇高手啊

本回答被提问者采纳
相似回答