#include<stdio.h>
int main()
{
    char str[100];
    int i, letter = 0, digit = 0, space = 0, other = 0;
    printf("请输入一行字符:");
    gets(str);
    for(i=0; str[i]!='\0'; i++)
    {
        if((str[i]>='a' && str[i]<='z') || (str[i]>='A' && str[i]<='Z'))
            letter++;
        else if(str[i]>='0' && str[i]<='9')
            digit++;
        else if(str[i]==' ')
            space++;
        else
            other++;
    }
    printf("字母个数:%d\n数字个数:%d\n空格个数:%d\n其他字符个数:%d\n", letter, digit, space, other);
    return 0;
}
用c语言:输入一行字符分别统计出其中英文字母、数字、空格和其他字符的个数。

原文地址: https://www.cveoy.top/t/topic/b1hh 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录