浙大版《C语言程序设计(第3版)》题目集 练习3-4 统计字符 (15分)

在这里插入图片描述

#include <stdio.h>
int main()
{
    int i, letter, blank, digit, other;
    char ch;
    letter = blank = digit = other = 0;
    for (i = 0; i < 10; i++)
    {
        scanf("%c", &ch);
        if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
            letter++;
        else if (ch == ' ' || ch == '\n')
            blank++;
        else if (ch >= '0' && ch <= '9')
            digit++;
        else
            other++;
    }
    printf("letter = %d, blank = %d, digit = %d, other = %d", letter, blank, digit, other);
    return 0;
}
发布了161 篇原创文章 · 获赞 117 · 访问量 6019

猜你喜欢

转载自blog.csdn.net/qq_44458489/article/details/105281634