Guest User

Untitled

a guest
Feb 20th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <stdio.h>
  2. /* count digits, white space, others */
  3. main()
  4. {
  5. int c, i, nwhite, nother;
  6. int ndigit[10];
  7. nwhite = nother = 0;
  8. for (i = 0; i < 10; ++i)
  9. ndigit[i] = 0;
  10. while ((c = getchar()) != EOF)
  11. if (c >= '0' && c <= '9')
  12. ++ndigit[c-'0'];
  13. else if (c == ' ' || c == 'n' || c == 't')
  14. ++nwhite;
  15. else
  16. ++nother;
  17. printf("digits =");
  18. for (i = 0; i < 10; ++i)
  19. printf(" %d", ndigit[i]);
  20. printf(", white space = %d, other = %dn",
  21. nwhite, nother);
  22. }
  23.  
  24. if (c >= '0' && c <= '9')
  25. ++ndigit[c-'0'];
  26.  
  27. if (c >= 0 && c <= 9)
  28.  
  29. ++ndigit[c-'0']
Add Comment
Please, Sign In to add comment