首页 > 其他 > 详细

分类统计字符个数(15 分)

时间:2018-07-03 20:38:45      阅读:452      评论:0      收藏:0      [点我收藏+]

统计字符个数
Description
输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。
Input
一行字符
Output
统计值
Sample Input
aklsjflj123 sadf918u324 asdf91u32oasdf/.’;123
Sample Output
23 16 2 4

#include<stdio.h>
int main()
{
    int char_num=0,int_num=0,space_num=0,other_num=0;
    char ch;
    while((ch=getchar())!=\n)
    {
        if(ch<=z&&ch>=a||ch<=Z&&ch>=A)
        {
            char_num++;
        }
        else if(ch<=9&&ch>=0)
        {
            int_num++;
        }
        else if(ch== )
        {
            space_num++;
        }
        else
        {
            other_num++;
        }
    }
    printf("字母个数:%d\n",char_num);
    printf("数字个数:%d\n",int_num);
    printf("空格个数:%d\n",space_num);
    printf("其他个数:%d\n",other_num);
}

 

分类统计字符个数(15 分)

原文:https://www.cnblogs.com/2228212230qq/p/9260456.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!