c语言练习题
题目要求:
输入一行字符,分别统计输入了多少个字母、数字、空格和其他字符。(不准用数组)
#include <stdio.h>
#include<stdbool.h>
int main()
{
void getC();
int number = 0, letter = 0, space = 0, other = 0;
char ch = '\0';
while ((ch = getchar()) != '\n')
{
if (ch == '\n')
{
break;
}
else if (ch >='a'&& ch<='z' || ch>= 'A' && ch<= 'Z')
{
letter++;
}
else if (ch >='0' && ch<= '9')
{
number++;
}
else if (ch == ' ')
{
space++;
}
else
{
other++;
}
}
printf("numer=%d\n", number);
printf("letter=%d\n", letter);
printf("space=%d\n", space);
printf("other=%d\n", other);
return 0;
}