c语言统计英文大小写字母,空格,数字,以及其他字符的个数并以#结束

    技术2022-07-11  82

    #include <stdio.h> int main(int argc, const char * argv[]) { char c; int letters=0,space=0,digit=0,others=0; while((c=getchar())!='#') { if ((c>='a'&&c<='z')||(c>='A'&&c<='Z')) { letters++; } else if(c==' ') { space++; } else if (c>='0'&&c<='9') { digit++; } else { others++; } } printf("letters=%d,space=%d,digit=%d,others=%d\n",letters,space,digit,others); return 0; }

    output:

    123456qwerty \\\\ # letters=6,space=1,digit=6,others=5 Program ended with exit code: 0
    Processed: 0.010, SQL: 9