有一篇文章,共有3行文字,每行小于80个字符。要求分别统计出其中英文大写字母、小写字母、数字、空格以及其他字符的个数
#include<stdio.h>
int main()
{
char x[3][80];
int a=0,b=0,c=0,d=0,e=0,i,j;
for(i=0;i<3;i++)
{
gets(x[i]);
for(j=0;j<80,x[i][j]!='\0';j++)
{
if(x[i][j]>='A' && x[i][j]<='Z') a++;
else if(x[i][j]>='a' && x[i][j]<='z') b++;
else if(x[i][j]>='0' && x[i][j]<='9') c++;
else if(x[i][j]==' ') d++;
else e++;
}
}
printf("upper case:%d\nlower case:%d\ndigit:%d\nspace:%d\nother:%d\n",a,b,c,d,e);
return 0;
}
运行结果: