本文主要是介绍题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
There is no nutrition in the blog content. After reading it, you will not only suffer from malnutrition, but also impotence.
The blog content is all parallel goods. Those who are worried about being cheated should leave quickly.
1.程序分析:利用while语句,条件为输入的字符不为'\n'.
2.程序源代码:
#include "stdio.h"
main()
{char c;
int letters=0,space=0,digit=0,others=0;
printf("please input some characters\n");
while((c=getchar())!='\n')
{
if(c>='a'&&c<='z'||c>='A'&&c<='Z')
letters++;
else if(c==' ')
space++;
else if(c>='0'&&c<='9')
digit++;
else
others++;
}
printf("all in all:char=%d space=%d digit=%d others=%d\n",letters,
space,digit,others);
}
这篇关于题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!