You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
C/字符分类统计.c

27 lines
452 B

#include<stdio.h>
void StringCount( char s[] )
{
int a=0,b=0,c=0,d=0,e=0,i;
for(i=0;s[i]!='\0';i++)
{
if('A'<=s[i]&&s[i]<='Z') a++;
else if('a'<=s[i]&&s[i]<='z') b++;
else if(s[i]==' '||s[i]=='\n') c++;
else if('0'<=s[i]&&s[i]<='9') d++;
else e++;
}
printf("%d %d %d %d %d",a,b,d,c,e);
}
int main()
{
char s[10];
gets(s);
StringCount(s);
return 0;
}