码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2015-10-27 07:08:05      阅读:234      评论:0      收藏:0      [点我收藏+]

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

#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语言】编写一个程序统计输入字符串中: 各个数字、空白字符、以及其他所有字符出现的次数。

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

原文地址:http://10740329.blog.51cto.com/10730329/1706524

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!