标题:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
只看楼主
笑死555
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2014-8-6
结帖率:100%
已结贴  问题点数:4 回复次数:2 
输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。

我编写的代码:
#include<stdio.h>
int main(void)
{
    char c;
    int letter=0,space=0,digit=0,others=0;
    printf("Please input some characters: ");
    while((c=getchar())!='\n')
    {
        if((c>'a'&&c<'z')||(c>'A'&&c<'Z'))
        letter++;
        else if(c==' ')
        space++;
        else if(c>='0'&&c<='9')
        digit++;
        else
        others++;
        printf("all in all  letter=%d, space=%d, digit=%d, others=%d\n",letter,space,digit,others);
    }
   
    return 0;
}

显示的结果:


我想问一下怎么能显示 直接输出一行,一步得到结论。
搜索更多相关主题的帖子: 英文字母 include letter others 统计 
2014-08-09 18:40
ditg
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:16
帖 子:852
专家分:1937
注 册:2014-4-10
得分:4 
#include<stdio.h>
int main(void)
{
    char c;
    int letter=0,space=0,digit=0,others=0;
    printf("Please input some characters: ");
    while((c=getchar())!='\n')
    {
        if((c>'a'&&c<'z')||(c>'A'&&c<'Z'))
        letter++;
        else if(c==' ')
        space++;
        else if(c>='0'&&c<='9')
        digit++;
        else
        others++;
        
    }
   printf("all in all  letter=%d, space=%d, digit=%d, others=%d\n",letter,space,digit,others);
    return 0;
}

梦想拥有一台龙芯3A-4000
2014-08-09 18:55
笑死555
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2014-8-6
得分:0 
回复 2 楼 ditg
多谢大神,可以运行了
2014-08-09 19:32



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-434862-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.272353 second(s), 9 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved