C语言:输入20个字符的字符串,分别统计数字,字母和其他字符的个数

请问一下如何编写这个c语言题目?谢谢。输入20个字符的字符串,分别统计数字,字母和其他字符的个数。

#include<stdio.h>
int main(void)
{
int i,letter=0,digit=0,other=0;
char ch;
printf("input 20 characters:");
for(i=1;i<=20;i++){
ch=getchar();
if(ch>='a'&&ch<='z'||ch>='A'&&ch<='Z')
letter++;
else if(ch>='0'&&ch<='9')
digit++;
else
other++;
}
printf("letter=%d,digit=%d,other=%d",letter,digit,other);
return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-01-03
#include<stdio.h>
int
main(void)
{
int
i,letter=0,digit=0,other=0;
char
ch;
printf("input
20
characters:");
for(i=1;i<=20;i++){
ch=getchar();
if(ch>='a'&&ch<='z'||ch>='A'&&ch<='Z')
letter++;
else
if(ch>='0'&&ch<='9')
digit++;
else
other++;
}
printf("letter=%d,digit=%d,other=%d",letter,digit,other);
return
0;
}

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网