编写一段程序,要求先输入一行字符,然后分别统计出其中英文字母、空格、数字和其他字符的个数,并输出其结果。

admin2017-12-03  34

问题 编写一段程序,要求先输入一行字符,然后分别统计出其中英文字母、空格、数字和其他字符的个数,并输出其结果。

选项

答案#include <stdio.h> main() {char c; int letter=0,space=0,digit=0,other=0; printf("请输入一行字符:\n"); while((c=getchar())!=’\n’) {if(c>=‘a’&&c<=‘z’||c>=‘A’&&c<=‘Z’) letter++, else if(c==‘’) space++; else if(c>=‘0’&&c<=‘9’) digit++; else other++; } printf("字母数=%d,空格数=%d,数字数=%d,其他字符=%d\n",letter,space,digit,other); }

解析
转载请注明原文地址:https://kaotiyun.com/show/Tmmq777K
0

相关试题推荐
最新回复(0)