为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

C
忄廿_94 2016-10-18 16:57:20
查看完整描述

1 回答

已采纳
?
JustWannaHugU

TA贡献452条经验 获得超796个赞

#include<stdio.h>
int main() 
{
	char ch;
	int letter=0,i,blank=0,number=0,others=0;  
	printf("请输入一串字符:");
	
	while((ch=getchar())!= '\n') 
	{
		if('a'<=ch && ch<='z' || 'A'<=ch && ch<='Z')  
		{
			letter++;
		}
		else if('0'<=ch&&ch<='9')
		{
			number++;
		}
		else if(ch==' ')
		{
			blank++;
		}
		else
		{
			others++;
		}
	}
	printf("英文字母:%d、空格:%d、数字:%d、其他字符:%d\n",letter,blank,number,others);
	return 0;
}


查看完整回答
反对 回复 2016-10-19
  • 1 回答
  • 0 关注
  • 1617 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信