.统计问题。输入一行字符,分别统计出其中英文字母、数字和其他字符的个数,以回车键作为结束标志。

能不能帮忙做做啊先谢谢啦

. #include<stdio.h>

void fun(char *a)
{
int m=0,n=0,p=0,q=0;
int i;
for(i=0;a[i]!='\0';i++)
{
if('A'<=a[i]&&a[i]<='Z'||'a'<=a[i]&&a[i]<='z') m++;
else if(a[i]>='0'&&a[i]<='9')++n;
else if(a[i]==' ')++p;
else ++q;
}
printf("字符的个数为:%d\n",m);
printf("数字的个数为:%d\n",n);
printf("空格的个数为:%d\n",p);
printf("其他字符的个数为:%d\n",q);
}
void main()
{
char s[20];
printf("输入字符串:");
gets(s);
puts(s);
fun(s);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-04-14
#include <stdio.h>
int main()
{
int letter=0,space=0,digit=0,others=0;
char c;
while((c=getchar())!='\n'){
if(c==' ')
space++;
else if(c>='1'&&c<='9')
digit++;
else if((c>='a'&&c<='z')||c>='A'&&c<='Z')
letter++;
else others++;
}
printf("The number of letters is:%d\n",letter);
printf("The number of spaces is:%d\n",space);
printf("The number of digits is:%d\n",digit);
printf("The number of other words is:%d\n",others);
return 0;
}
第2个回答  2012-04-10
什么语言编?高级语言还是汇编啊?还是C?
第3个回答  2010-04-14
#include <stdio.h>
int main()
{
int letter=0,space=0,digit=0,others=0;
char c;
while((c=getchar())!='\n'){
if(c==' ')
space++;
else if(c>='1'&&c<='9')
digit++;
else if((c>='a'&&c<='z')||c>='A'&&c<='Z')
letter++;
else others++;
}
printf("The number of letters is:%d\n",letter);
printf("The number of spaces is:%d\n",space);
printf("The number of digits is:%d\n",digit);
printf("The number of other words is:%d\n",others);
return 0;
}
第4个回答  2012-04-10
什么语言编?高级语言还是汇编啊?还是C?
相似回答