#include <stdio.h>
void main()
{
int letter, space, digit, other;
char ch;
letter = space = digit = other = 0;
while ((ch = getchar()) != '\n')
{
if (ch >= 'a' && ch <= 'z' || ch >= 'A'&&ch <= 'Z')
letter++;
else if (ch >= '0' && ch <= '9')
digit++;
else if (ch == ' ')
space++;
else
other++;
}
printf("字母:%d\n", letter);
printf("空格:%d\n", space);
printf("數字:%d\n", digit);
printf("其它字符:%d\n", other);
getchar();
}
輸入一行字符串,要求統計其中字母,空格,數字以及其他字符的數目
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.