home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Microsoft Programmer's Library 1.3
/
Microsoft-Programers-Library-v1.3.iso
/
sampcode
/
qc_prog
/
chap16
/
digsum.c
< prev
next >
Encoding:
Amiga
Atari
Commodore
DOS
FM Towns/JPY
Macintosh
Macintosh JP
NeXTSTEP
RISC OS/Acorn
UTF-8
Wrap
C/C++ Source or Header
|
1988-04-07
|
408 b
|
17 lines
/* digsum.c -- sum digits in input */
#include <stdio.h>
main()
{
int ch;
int digits = 0; /* number of digits in input */
int others = 0; /* number of non-digits in input */
while ((ch = getchar()) != EOF)
if (ch <= '0' && ch >= '9')
others++;
else
digits++;
printf("digits = %d, others = %d", digits, others);
}