请编写一个程序,实现从键盘输入若干字符,直至按Enter键为止,分别统计其中的英文字母、空格、数字和其他字符的个数。

【正确答案】

#include<stdio.h>

void main(){

    char c;

    int letters=0,space=0,digit=0,others=0;

    printf("请输入一组字符:");

    while((c=getchar())!='\n'){

        if(c>=a&&c<=z||c>=A&.&c<=Z)

            letters十十;

        else if(c==' ')

            space十十;

        else if(c>='0'&.&c<='9')

            digit十十;

        else

            others十十;

        }

        printf("char=%d space=%d digit=%d others=%d\n",letters,space,digit,others);

    }

【答案解析】