作业3-3 输入 15 个字符,统计其中英文字母、空格或回车、数字字符和其他字符的个数

#include <stdio.h>
int main(void)
{
    char ch;
    int blank, digit, i, letter, other;

    blank = digit = letter = other = 0;
    printf("Enter 15characters:");
    for(i = 1; i <= 15; i++){
        ch = getchar();
    
    if ((ch >= 'a' && ch<= 'z' )||(ch >= 'A' && ch <= 'Z'))
      letter ++;
    
    else if (ch == 32)//32是空格的十进制代号
      blank ++;
    

    else if ((ch >= '0') &&(ch<= '9'))/字符的代号
      digit ++;
    
    else
      other ++;
    }
    printf("letter = %d, blank = %d, digit = %d, other = %d\n", letter, blank, digit, other);

    return 0;
}

posted @ 2013-10-24 09:56  涅墨西斯  阅读(1210)  评论(0编辑  收藏  举报