fork download
  1. #include <ctype.h>
  2. #include <stdio.h>
  3.  
  4. int main(void) {
  5. int sum = 0;
  6. for (;;) {
  7. int ch = getchar();
  8. if (!isdigit((unsigned char)ch)) break; // leave loop with ENTER, EOF, 'a', ...
  9. sum += ch - '0';
  10. }
  11. printf("sum of digits is %d.\n", sum);
  12. return 0;
  13. }
  14.  
Success #stdin #stdout 0s 5360KB
stdin
452387643264873257452354235423748723642364723546253465236452354723
stdout
sum of digits is 282.