分别统计输入中字母、数字的个数.c 317 B

12345678910111213141516171819
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. int main() {
  4. char ch;
  5. int letters = 0, digits = 0;
  6. while ((ch = getchar()) != EOF) {
  7. if (isalpha(ch)) {
  8. letters++;
  9. } else if (isdigit(ch)) {
  10. digits++;
  11. }
  12. }
  13. printf("%d %d\n", letters, digits);
  14. return 0;
  15. }