用for语句怎么写1.输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。

1.输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。用for语句写


#include<stdio.h>
int main()
{
        char ch[50];
        int i,letter=0,digit=0,blank=0,other=0;
        for(i=0;ch[i-1]!='\n';i++)
                ch[i]=getchar();
        for(i=0;ch[i]!='\n';i++){
                if(ch[i]>='A'&&ch[i]<='Z' || ch[i]>='a'&&ch[i]<='z' )
                        letter++;
                else if(ch[i]>='0'&&ch[i]<='9')
                        digit++;
                else if(ch[i]==' ')
                        blank++;
                else
                other++;
        }
        printf("字母:%d,数字:%d,空格:%d,其他:%d\n",letter,digit,blank,other);

        return 0;

}