您的位置:首页 > 其它

5.4输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数

2019-01-24 18:00 477 查看
//C程序设计第四版(谭浩强)
//章节:第五章 循环结构程序设计
//题号:5.4
//题目:输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。
#include <stdio.h>
int main()
{
char c;
int letter=0,space=0,number=0,other=0;
printf("请输入一行字符:");
while((c=getchar())!='\n')
{
if(c>='a'&&c<='z'||c>='A'&&c<='Z')
letter++;
else if(c==' ')
space++;
else if(c>='0'&&c<='9')
number++;
else
other++;
}
printf("letter:%d\nspace:%d\nnumber:%d\nother:%d\n",letter,space,number,other);
return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐