度 C语言编程序:用数组的方法实现程序,从键盘输入不超过50个字符,统计其中英文字母。空



C语言编程序:用数组的方法实现程序,从键盘输入不超过50个字符,统计其中英文字母。空格字符,数字字符以及其他

#include <stdio.h>
int main()
{
     char c[50];
     int i,el=0,sp=0,nu=0,other=0; 
     gets(c);//输入字符串 
     
     for(i=0; i<strlen(c); i++)//strlen返回字符串长度 
     {
             if((c[i]>='A' && c[i]<='Z')||(c[i]>='a' && c[i]<='z'))
                  el++;
             else if(c[i]>='0'&&c[i]<='9')
                 nu++;
             else if(c[i]==' ')
                 sp++;
             else 
                  other++;
     }
     printf("英文字母个数=%d\n数 字 个 数 =%d\n空 格 字 数 =%d\n其他字符个数=%d\n",el,nu,sp,other);
     return 0;
}

测试结果如下:

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-11-10
#include <stdio.h>
void main()
{
char c,str[51];
int i=0,letters=0,space=0,digit=0,others=0;
printf("请输入不超过50个字符\n");
gets(str);
while((c=str[i++])!=0)
{
if(c>='a'&&c<='z'||c>='A'&&c<='Z')
letters++;
else if(c==' ')
space++;
else if(c>='0'&&c<='9')
digit++;
else
others++;
}
printf("英文字符:%d 空格:%d 数字:%d 其他:%d\n",letters,space,digit,others);
}本回答被提问者采纳

相关了解……

你可能感兴趣的内容

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