您的位置:首页 > 其它

输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。

2014-05-04 18:47 375 查看
#include "stdio.h"
#define N 30
void main()
{
char i
;
int j;
int words,spaces,numbers,others;
words=spaces=numbers=others=0;//下面要自加的变量一定要初始化为0
printf("please input the passage.\n");
gets(i);
//for(j=0;j<30;j++)
for(j=0;j<N&&i[j]!='\0';j++)
{
//if(i[j]==' ')
//是两个等号,不是一个等号
if(i[j]==' ')
spaces++;
//else if(i[j]>='A'&&i[j]<='Z'||i[j]>='a'&&i[j]<='z')//&& 和 || 之间要加括号:(...&&...)||(...&&...)
else if((i[j]>='A'&&i[j]<='Z')||(i[j]>='a'&&i[j]<='z'))
words++;
else if(i[j]>='0'&&i[j]<='9')
numbers++;
else
others++;
}
printf("the words are:%d\n",words);
printf("the spaces are:%d\n",spaces);
printf("the others are:%d\n",others);
printf("the numbers are:%d\n",numbers);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐