您的位置:首页 > 编程语言 > C语言/C++

【C语言】编写一个程序统计输入字符串中: 各个数字、空白字符、以及其他所有字符出现的次数。

2015-10-26 20:45 966 查看
#include <stdio.h>
int main()
{
char s[20];
char num=0;
int num_count=0;
int space_count=0;
int other_count=0;
while((num=getchar())!='\n')
{
if(num>='0'&&num<='9')
{
num_count++;
}
else if(num==' ')
{
space_count++;
}
else
{
other_count++;
}
}
printf("num_count=%d\n",num_count);
printf("space_count=%d\n",space_count);
printf("other_count=%d\n",other_count);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  C语言