fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int num,temp,rem,sum=0;
  5.  
  6. printf("enter a number : ");
  7. scanf("%d",&num);
  8.  
  9. temp=num;
  10.  
  11. while(temp!=0){
  12. rem=temp%10;
  13. sum=sum+rem;
  14. temp=temp/10;
  15. }
  16.  
  17. printf("sum of digits: %d",sum);
  18.  
  19. return 0;
  20. }
  21.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
enter a number : sum of digits: 22