/*
本题要求编写程序,输入一行字符,统计其中数字字符、空格和其他字符的个数。建议使用while语句编写。
输入
输入在一行中给出若干字符,最后一个回车表示输入结束,不算在内。
输出
在一行内按照
blank = 空格个数, digit = 数字字符个数, other = 其他字符个数
的格式输出。请注意,等号的左右各有一个空格,逗号后有一个空格。
*/
#include <stdio.h>
int main()
{
char c;
int blank = 0, digit = 0, other = 0;
while ((c = getchar()) != '\n')
{
if (c == ' ')
blank++;
else if (c >= '0' && c <= '9')
digit++;
else
other++;
}
printf("blank = %d, digit = %d, other = %d\n", blank, digit, other);
return 0;
}
6万+

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



