fork download
  1. #include <stdio.h>
  2.  
  3. int sum(int);
  4.  
  5. int main(void) {
  6.  
  7. int num,z;
  8.  
  9. printf("Enter any 5 digit number: ");
  10. scanf("%d",&num);
  11.  
  12. z=sum(num);
  13.  
  14. printf("The sum of the digits of %d is %d");
  15.  
  16. return 0;
  17. }
  18. int sum(int x)
  19. {
  20. if(x==0)
  21. return 0;
  22. else
  23. return x%10+sum(x/10);
  24. }
Success #stdin #stdout 0s 4384KB
stdin
11111
stdout
Enter any 5 digit number: The sum of the digits of 0 is 0