Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2. int main()
  3. {
  4.  
  5. /* conta cifre, spazi e tutti gli altri caratteri */
  6. int c, i, nwhite, nother, ndigit[10];
  7. nwhite=nother=0;
  8. for (i=0; i<10; i++)
  9. ndigit[i] = 0; //ogni volta i deve valere 0
  10. while ((c=getchar())!=EOF)
  11. {
  12. switch(c)
  13. {
  14. case '0': case '1': case '2': case '3': case '4':
  15. case '5': case '6': case '7': case '8': case '9':
  16. ndigit[c-'0']++;
  17. break;
  18. case ' ':
  19. case '\n':
  20. case '\t':
  21. nwhite++;
  22. break;
  23. default:
  24. nother++;
  25. break;
  26. }
  27. }
  28. printf("cifre =");
  29. for (i=0; i<10; i++)
  30. printf(" %d", ndigit[i]);
  31. printf(", spazi = %d, altri = %d\n", nwhite, nother);
  32. return 0;
  33.  
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement