fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int n, sum = 0;
  5.  
  6. printf("Enter a number: ");
  7. scanf("%d", &n);
  8.  
  9. while (n > 0) {
  10. sum += n % 10;
  11. n /= 10;
  12. }
  13.  
  14. printf("The sum of digits is %d\n", sum);
  15.  
  16. return 0;
  17. }
Success #stdin #stdout 0s 5280KB
stdin
678
stdout
Enter a number: The sum of digits is 21