From f5c973dfe7bc4d8ecf4c4691076064647db17741 Mon Sep 17 00:00:00 2001 From: NaiJi Date: Mon, 22 Apr 2024 00:30:40 +0400 Subject: [PATCH] 1.13 --- The C Programming Language/1.13.c | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 The C Programming Language/1.13.c diff --git a/The C Programming Language/1.13.c b/The C Programming Language/1.13.c new file mode 100644 index 0000000..47691f6 --- /dev/null +++ b/The C Programming Language/1.13.c @@ -0,0 +1,32 @@ +#include + +main() +{ + int c, i, nwhite, nother; + int ndigit[10]; + + nwhite = nother = 0; + for (i = 0; i < 10; ++i) + ndigit[i] = 0; + + while ((c = getchar()) != EOF) + if (c >= '0' && c <= '9') + ++ndigit[c-'0']; + else if (c == ' ' || c == '\t') + ++nwhite; + else if (c == '\n') + { + ++nwhite; + printf("digits = "); + for (i = 0; i < 10; ++i) + printf(" %d", ndigit[i]); + printf(", white space = %d, other = %d\n", nwhite, nother); + } + else + ++nother; + + printf("digits = "); + for (i = 0; i < 10; ++i) + printf(" %d", ndigit[i]); + printf(", white space = %d, other = %d\n", nwhite, nother); +}