标题: c语言 统计不同类型字符数 [打印本页]

作者: liuda    时间: 2015-1-22 02:46
标题: c语言 统计不同类型字符数
#include<stdio.h>//统计不同类型字符数
void main()
{char c;
        int e=0,s=0,n=0,o=0;//这样输入是错误的:e=s=n=o=1,为什么呢?
printf("please input random characteristics,use enter to end the string\n");
for(;(c=getchar())!='\n';)//斜杠好像被我打反了
{
if((c>=65&&c<=90)||(c>=97&&c<=122))
e++;
else if((c>=48&&c<=57))
n++;
else if(c==32)
s++;
else
o++;
}
printf("the number of english characteristic is %d\n",e);
printf("the number of  space is %d\n",s);
printf("the number of number is %d\n",n);
printf("the number of other characteristics is %d\n",o);
}






欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1