题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
#include <stdio.h>
main()
{
int a,b,c,d;
char s;
a = 0;b = 0;c = 0;d = 0;
printf("Please input some characters :");
while( (s = getchar())!= '\n')
{
if((s >= 'a' && s <= 'z')||(s >= 'A' && s <= 'Z'))
a++;
else if(s >= '0' && s <= '9')
b++;
else if( s = ' ' )
c++;
else
d++;
}
printf("all in all:char=%d space=%d digit=%d others=%d\n",a,c,b,d);
return 0;
}
网友评论