整数各位数字求和.c 203 B

1234567891011121314151617181920
  1. #include <stdio.h>
  2. int sum(int x) {
  3. int result = 0;
  4. while(x > 0) {
  5. result += x % 10;
  6. x /= 10;
  7. }
  8. return result;
  9. }
  10. int main() {
  11. int x;
  12. scanf("%d", &x);
  13. printf("%d", sum(x));
  14. return 0;
  15. }