统计字母、数字、空格和其他字符的个数。

  • 格式:wps
  • 大小:13.50 KB
  • 文档页数:2

统计字母、数字、空格和其他字符的个数。

输入一串不多于50个的字符,统计其中的字母、数字、空

格和其他字符的个数,并输出。

#include

#include

int main()

{

char str[50];

int len,i;

char c;

int number=0,letter=0,space=0,other=0;

printf("输入一串不超过50个字符的符号串:");

gets(str);

for(i=0;i

{

c=str[i];

if(c>='a'&&c<='z'||c>='A'&&c<='Z')

letter++;

else if(c>='0'&&c<='9')

number++;

else if(c==' ')

space++;

else

other++;

}

printf("%d,%d,%d,%d",letter,number,space,other);

}