【程序7】
题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
#include<stdio.h>
int main()
{
int letter,space,digit,other;
letter=space=digit=other=0;
char ch;
printf("Enter a line characters:/n");
while(ch!='/n')
{
ch=getchar();
if((ch>='a' && ch<='z') || (ch>='A' && ch<='Z'))
letter++;
else if(ch==' ')
space++;
else if(ch>='0' && ch<='9')
digit++;
else
other++;
}
printf("letter=%d/nspace=%d/ndigit=%d/nother=%d/n",letter,space,digit,other);
return 0;
}