C语言实现统计字符类型:字母、数字、空格和其他字符
#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;
}
原文地址: https://www.cveoy.top/t/topic/nlVx 著作权归作者所有。请勿转载和采集!