编写一个程序,输入一行字符,以回车结束,分别统计出其中的英文字母、空格、数字和其他字符的数。

 我来答
帐号已注销
2021-01-18 · TA获得超过77万个赞
知道小有建树答主
回答量:4168
采纳率:93%
帮助的人:150万
展开全部

#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;

}

扩展资料:

字符包括字母、数字、运算符号、标点符号和其他符号,以及一些功能性符号。字符在计算机内存放,应规定相应的代表字符的二进制代码。代码的选用要与有关外围设备的规格取得一致。这些外围设备包括键盘控制台的输入输出、打印机的输出等等。

字符作输入时,要自动转换为二进制代码存于机内;输出时,计算机内二进制代码自动转化为字符,两者的转换全是靠外围设备实现的。字符是数据结构中最小的数据存取单位。

参考资料来源:百度百科-字符

百度网友1bbbb466b
推荐于2018-02-27 · 超过17用户采纳过TA的回答
知道答主
回答量:41
采纳率:0%
帮助的人:0
展开全部
#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;
}
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友076061257
2010-04-14
知道答主
回答量:1
采纳率:0%
帮助的人:0
展开全部
干哥哥
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式