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.  
  9. int sum=0;
  10.  
  11. while(n>0){
  12. int ld= n%10;
  13. sum= sum+ld;
  14. n=n/10;
  15. }
  16. printf(" The sum is %d",sum);
  17. return 0;
  18. }
  19.  
Success #stdin #stdout 0s 5320KB
stdin
2244
stdout
Enter the number:  The sum is 12