Files
first-repo/arrays.c
2025-02-06 12:54:34 +02:00

22 lines
496 B
C

#include <stdio.h>
int main() {
int ch, n_whitesp, n_other;
int n_digit[10] = {0}; /* initialize array with zeroes */
n_whitesp = n_other = 0;
while ((ch = getchar()) != EOF)
if (ch >= '0' && ch <= '9')
++n_digit[ch - '0'];
else if (ch == ' ' || ch == '\n' || ch == '\t')
++n_whitesp;
else
++n_other;
printf("digits = ");
for (int i = 0; i < 10; ++i)
printf(" %d", n_digit[i]);
printf(", white space = %d, other = %d\n", n_whitesp, n_other);
}