Character statistics: input line of characters, respectively, the statistics of the number of letters, spaces, numbers and other characters in them.

#include <stdio.h>

void main() {
    int letters = 0, spaces = 0, digits = 0, others = 0;
    char c;
    while ((c = getchar()) != '\n') {
        if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
            letters++;
        else if (c == ' ')
            spaces++;
        else if (c >= '0' && c <= '9')
            digits++;
        else
            others++;
    }
    printf("l=%d,d=%d,s=%d,o=%d", letters, digits, spaces, others);
}
Published 139 original articles · won praise 4 · Views 930,000 +

Guess you like

Origin blog.csdn.net/qq_38490457/article/details/104808460