fork download
  1. #include <stdio.h>
  2. int main ()
  3. {
  4.  
  5. int right_digit; /* right most digit in the number */
  6. int number; /* the inputted number */
  7. int sum_of_digits = 0; /* the sum of the digits processed */
  8.  
  9. printf ("Enter your number: ");
  10. scanf ("%d", &number);
  11.  
  12. while (number != 0)
  13. {
  14. right_digit = number % 10;
  15. printf ("right digit = %d", right_digit);
  16. sum_of_digits += right_digit;
  17. number = number / 10;
  18. printf (", number = %d\n", number);
  19. }
  20.  
  21. printf ("\n");
  22. printf ("Sum_of_digits = %d\n", sum_of_digits);
  23.  
  24. return (0);
  25. }
Success #stdin #stdout 0.01s 5268KB
stdin
Standard input is empty
stdout
Enter your number: right digit = 4, number = 2185
right digit = 5, number = 218
right digit = 8, number = 21
right digit = 1, number = 2
right digit = 2, number = 0

Sum_of_digits = 20