#include <stdio.h> int main () { int c = 0;
int num_count = 0;
int emp_count = 0;
int els_count = 0;
while ((C = getchar ()) != eof) { if (c >=
' 0 ') && (c <= ' 9 ')) { num_count ++
; } else if (c == ' ') { emp_count ++; &NBSP;&NBSP;&NBSP;&NBSP} else {
els_count ++; } &NBSP;&NBSP;&NBSP;&NBSP;&NBSP} printf ("%d %d
%d ", Num_count,emp_count,els_count); return 0; }
In addition, Method 2 compares with the method 1
(1) Each number can be calculated specifically several times.
(2) a function isspace () is used for the space.
#include <stdio.h> int main () { int c = 0;
int num_count = 0;
int emp_count = 0;
int els_count = 0;
int arr[10] ={0};
int i = 0;
while ((C = getchar ()) != eof) { if (c >= ' 0 ' &&c <= ' 9 ') { arr[c-' 0 '] ++; } else if (Isspace (c)) {
emp_count ++; } else { els_count ++; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP} }
printf ("emp_count: %d\n", Emp_count);
printf ("els_count: %d\n", Els_count); for ( ; i<10;i++) { printf ("%d:%d\n", i, arr[i) ); &NBSP;&NBSP;&NBSP} return 0; }