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

C语言练习题:输入一行字符,统计其中的英文字符、数字字符、空格和其他字符的个数。

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

C语言练习题:输入一行字符,统计其中的英文字符、数字字符、空格和其他字符的个数。

输入一行字符,统计其中的英文字符、数字字符、空格和其他字符的个数。

输入提示信息:"Please input a  string:"

输入字符串用gets() 输出提示信息和格式:

"English character:  %dn"

"digit character:  %dn"

"space:  %dn"

"other character:  %dn"

#include 
#include 
#define ARR_SIZE 80
int main()
{      		 
    char str[ARR_SIZE]; //1
    int  len, i, letter = 0, digit = 0, space = 0, others = 0; //1
    printf("Please input a  string:"); //1
    gets(str); //1
    for (i = 0; str[i] != ''; i++) //1
    {      		 
        if (str[i] >= 'a' && str[i] <= 'z' || str[i] >= 'A' && str[i] <= 'Z') //1
            letter ++;				//统计英文字符
        else if (str[i] >= '0' && str[i] <= '9' ) //1
            digit ++;				//统计数字字符
        else if (str[i] == ' ' ) //1
            space ++;				//统计空格
        else
            others ++;				//统计其他字符的个数
    } 
    printf("English character:  %dn", letter); //1
    printf("digit character:  %dn", digit); //1
    printf("space:  %dn", space); //1
    printf("other character:  %dn", others); //1
    return 0;

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

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

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