统计出字符串中英文字母、空格、数字和其它字符的个数。
/**
* Created by 冲哥 on 2021/3/17.
* 统计出字符串中英文字母、空格、数字和其它字符的个数。
*/
#include<stdio.h>
int main()
{
char ch;
int letter_num=0;
int space_num=0;
int digit_num=0;
int other_num=0;
printf("请输入字符串:\n");
while((ch=getchar())!='\n')
{
if(ch>='a'&&ch<='z'||ch>='A'&&ch<='Z')
letter_num++;
else if(ch==' ')
space_num++;
else if(ch>='0'&&ch<='9')
digit_num++;
else
other_num++;
}
printf("您所输入的字符串中:英文字母有%d个,空格有%d个,数字有%d个,剩余其他字符%d个\n",letter_num,space_num,digit_num,other_num);
return 0;
}
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有