首页 > 试题广场 >

输入一串字符,分别统计出英文字母、空格、数字和其他字符的个数

[问答题]

输入一串字符,分别统计出英文字母、空格、数字和其他字符的个数

void main ()

{ char c;

int letters=0, space=0, digit=0, other=0;

printf (“please input a string:\n”);

while (__ (c=getchar())!=’\n’ __)

{ if (_____ c>=’a’ && c<=’z’ || c>=’A’ && c<=’Z’ ____)

letters++;

else if(c= =’  ’)

space++;

else if(c>=’0’ && c<=’9’)

_____ digit++ _____;

else

other++;

}

printf (“letters’ number: %d\nspace’s number: %d\ndigit’s number: %d\nother’s number: %d\n”, letters, space, digit, other);

}

这道题你会答吗?花几分钟告诉大家答案吧!