用ASCLL判断输入元素

数字0-9的ASCII码为:048到057
大写字母A-Z的ASCII为:065-090
小写字母a-z的ASCII为:097到122

判断字符是数字还是大小写字母

int main()

{

        input=getchar();//获取输入的字符
        if(input <= 32)
                printf("You have input a control  character!!\n");
        else if(input >= 48 && input <= 57)    //数字;
        {
                for( i=48;i<58;i++)
                {
                        if(input==i)
                                break;
                }
                printf("You put a number,ranging from 0--9!\n The number is %d!\n ",i);
        }
        else if(input >=65 && input <=90 )  //大写字母;
        {
                for( i=65; i<=90; i++)
                {
                        if(input==i)
                                break;
                }
                printf("You have put a uppercase! Ranging from A--Z!\nThe number is %d!\n",i);
        }
        else if(input >=97 && input <=122)   //小写字母
        {
                for( i=97;i<=122;i++)
                {
                        if(i==input)
                                break;
                }
                printf("You have input a lowercase! Ranging from a--z!\nThe number is %d\n",i);
        }
        else  
                printf("You have input a other character!\n");
        }

 

posted @ 2018-08-10 16:39  三儿啊  阅读(165)  评论(0编辑  收藏  举报