当前位置:好百科>百科问答>输入一行字符,分别统计出其中的英文字母、空格、数字和其他字符的个数

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

2025-01-25 20:15:01 编辑:zane 浏览量:585

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

的有关信息介绍如下:

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

1 while语句:#includeint main(void){ //输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。 char ch; int char_num=0,kongge_num=0,int_num=0,other_num=0; while((ch=getchar())!='\n')//回车键结束输入,并且回世备车符不计入 { if(ch>='a'&&ch<='z'||ch<='z'&&ch>='a') { char_num++; } else if(ch==' '陆饥) { kongge_num++; } else if(ch>='0'&&ch<='9') { int_num++; } else { other_num++; } } printf("字母= %d,空格= %d,数字= %d,其它= %d\n",char_num,kongge_num,int_num,other_num); return 0;}2 ,do while语句:#includeint main(void){ //输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。 char ch; int char_num=0,kongge_num=0,int_num=0,other_num=0; do { if(ch>='a'&&ch搜悉毁<='z'||ch<='z'&&ch>='a') { char_num++; } else if(ch==' ') { kongge_num++; } else if(ch>='0'&&ch<='9') { int_num++; } else { other_num++; } } while((ch=getchar())!='\n')//回车键结束输入,并且回车符不计入 printf("字母= %d,空格= %d,数字= %d,其它= %d\n",char_num,kongge_num,int_num,other_num); return 0;}

版权声明:文章由 好百科 整理收集,来源于互联网或者用户投稿,如有侵权,请联系我们,我们会立即处理。如转载请保留本文链接:https://www.haobaik.com/answer/263308.html
热门文章