输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数,C语言编程如下:
#include<stdio.h>
void main(){
char c;
int letter=0,space=0,digit=0,other=0;
while((c=getchar())!='\n'){
if(c>='a'&&c<='z'||c>='A'&&c<='Z') letter++;
else
if(c==' ') space++;
else
if(c>='0'&&c<='9') digit++;
else other++;
}
printf("letter=%d,space=%d,digit=%d,other=%d\n",letter,space,digit,other);
}