Description
输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。
Input
一行字符
Output
统计值
Sample Input 
aklsjflj123 sadf918u324 asdf91u32oasdf/.';123
Sample Output
23 16 2 4
#include<Stdio.h>
int main()
{
int letter=0,number=0,blank=0,others=0;
char c;
printf("Input your string:");
while((c=getchar())!='\n')
{
if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
{
letter++;
}
else if(c>='0'&&c<='9')
{
number++;
}
else if(c==' ')
{
blank++;
}
else {
others++;
}
}
printf("字母为:%d\n数字:%d\n空格为:%d\n其它字符为:%d\n",letter,number,blank,others);
return 0;
}
本文介绍了一个简单的C语言程序,用于统计用户输入字符串中的英文字母、数字、空格和其他字符的数量。通过逐个检查输入流中的每个字符并将其分类,程序能够提供详细的字符分布情况。
1062

被折叠的 条评论
为什么被折叠?



