栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C语言练习题,从键盘任意输入一个字符,编程判断该字符是数字字符、英文字母、空格还是其他字符

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C语言练习题,从键盘任意输入一个字符,编程判断该字符是数字字符、英文字母、空格还是其他字符

从键盘任意输入一个字符,编程判断该字符是数字字符、英文字母、空格还是其他字符。
**输入格式要求:提示信息:"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!
#include 
main()
{        
    char  ch;
    printf("Press a key and then press Enter:");
    ch = getchar();
    if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z')
    {        
        printf("It is an English character!n");
    }
    else if (ch <= '9' && ch >= '0')
    {        
        printf("It is a digit character!n");
    }
    else if (ch == ' ')
    {        
        printf("It is a space character!n");
    }
    else
    {        
        printf("It is other character!n");
    }
}        

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/352466.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号