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