输入一行字符,以回车结束,统计其中0~9每个数字出现的次数
输入一行字符,以回车结束,分别统计其中大写英文字母,小写英文字母,空格以及其他字符的个数
2018-06-10 10:23
程序代码:#include <stdio.h>
int main()
{
int letter=0,space=0,digit=0,others=0;
char c;
while((c=getchar())!='\n'){
if(c==' ')
space++;
else if(c>='1'&&c<='9')
digit++;
else if((c>='a'&&c<='z')||c>='A'&&c<='Z')
letter++;
else others++;
}
printf("The number of letters is:%d\n",letter);
printf("The number of spaces is:%d\n",space);
printf("The number of digits is:%d\n",digit);
printf("The number of other words is:%d\n",others);
return 0;
}
2018-06-10 11:02