From b596a89ad338c9345d7952899caa3960aca841a6 Mon Sep 17 00:00:00 2001 From: pitnqh5lc <3321198270@qq.com> Date: Sat, 19 Feb 2022 22:31:59 +0800 Subject: [PATCH] =?UTF-8?q?Add=20=E5=AD=97=E7=AC=A6=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 字符分类统计 | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 字符分类统计 diff --git a/字符分类统计 b/字符分类统计 new file mode 100644 index 0000000..73ebbb9 --- /dev/null +++ b/字符分类统计 @@ -0,0 +1,38 @@ +字符分类统计:从键盘输入一个长度为10的字符串,分别统计出其中大写字母、小写字母、数字、空格和其他字符的个数并分别输出。 +代码: +#include +#include +int main() +{ + char str[100]; + int i,num = 0,space = 0,capital = 0,lowercase = 0,others = 0; + gets(str); + for(i=0; i='0'&&str[i]<='9') + num++; + if(str[i] ==' ') + space++; + if(str[i]>='A'&&str[i]<='Z') + capital ++; + if(str[i]>='a'&&str[i]<='z') + lowercase++; + else + others++; + } + } + printf("数字数量为:%d\n大写字母数量为:%d\n小写字母数量为:%d\n空格数量为:%d\n其他字符:%d\n",num,capital,lowercase,space,others); +} +运行结果时间: +ADxe12. ; +数字数量为:2 +大写字母数量为:2 +小写字母数量为:2 +空格数量为:1 +其他字符:7 + +-------------------------------- +Process exited after 10.28 seconds with return value 0 +请按任意键继续. . . \ No newline at end of file