输入一行字符,分别统计出英文字母,空格,数字,和其它字符的个数.

#include <stdio.h>

#include <stdlib.h>

int main()

{

int a=0,b=0,c=0,d=0,ch;

while((ch=getchar())!='\n')

{

if(ch>='0'&&ch<='9')

a++;

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

b++;

else if(ch==' ')

c++;

else

d++;

}

printf("数字个数为: %d\n", a);

printf("字母个数为: %d\n", b);

printf("空格个数为: %d\n", c);

printf("其他字符个数为: %d\n", d);

system("pause");

return 0;

}

猜你喜欢

转载自blog.csdn.net/qq_42164474/article/details/80286180