输入一行字符,分别统计出其中的英文字母.空格.数字.和其他字符的个数!因为刚刚开始学想想好象很容易!我做来做去总是有错误!希望大家可以赐教!尽量不要用太复杂的方法!多谢!
參考答案:#include <stdio.h>
#include <string.h>
void main()
{
char a[1000], i, x1, x2, x3, x4;
scanf("%s", a);
x1 = 0; x2 = 0; x3 = 0; x4 = 0;
for (i = 0; i < strlen(a); i++)
if (((a[i] >='a') && (a[i] <= 'z')) || ((a[i] >='A') && (a[i] <= 'Z'))) x1 ++;
else if (a[i] == ' ') x2++;
else if ((a[i] >= '0') && (a[i] <= '9')) x3++;
else x4++;
printf("%d %d %d %d\n", x1, x2, x3, x4);
}